diff --git a/LDP/txt2db/sample.txt b/LDP/txt2db/sample.txt index 49fc608d..f7dc35f0 100644 --- a/LDP/txt2db/sample.txt +++ b/LDP/txt2db/sample.txt @@ -1,4 +1,19 @@ -=Introduction|intro= +=Introduction|intro-to-the-program= + +The following list should be rendered as a qandaset: + +Q: Why? +A: Why not? + +Multiple questions and multiple answers: + +Q: Why? +Q: Why2? +A: Why not? +A: Why not2? + +Q: Why? +A: Why not? Simple List diff --git a/LDP/txt2db/txt2db.pl b/LDP/txt2db/txt2db.pl index 7557d08c..e870171e 100755 --- a/LDP/txt2db/txt2db.pl +++ b/LDP/txt2db/txt2db.pl @@ -12,7 +12,9 @@ my($level1, $level3, $orderedlist, $listitem, - $para); + $para, + $qandaset, + $qandaentry); my($line); my($id, $title); @@ -59,7 +61,6 @@ open(DB, "> $dbfile") || die "txt2db: cannot write to $dbfile ($!)\n"; print DB $buf, "\n"; close(DB); -print "txt2db: created $dbfile from $txtfile\n"; exit(0); # ----------------------------------------------------------- @@ -87,9 +88,9 @@ sub proc_txt { next; } - # pass DocBook right on through + # pass DocBook right on through -- must be in or tags # - if ($line =~ /^\n"; $orderedlist = 1; @@ -155,6 +157,7 @@ sub proc_txt { $listitem = 1; $para = 1; } elsif ($line =~ /^\*/) { + &closeqandaset; if ($list == 0) { $buf .= "\n\n"; $list = 1; @@ -164,9 +167,23 @@ sub proc_txt { $line =~ s/^/\n/; $listitem = 1; $para = 1; - } - else { - &closeorderedlist; + } elsif ($line =~ /^Q:/) { + $line =~ s/^Q://; + $line = "" . $line . "\n"; + unless ($qandaentry == 1) { + $line = "\n" . $line; + $qandaentry = 1; + } + if ($qandaset == 0) { + $line = "\n". $line; + $qandaset = 1; + } + + } elsif ($line =~ /^A:/) { + $line =~ s/^A://; + $line = "" . $line . "\n"; + } else { + &closeqandaset; if ( $para == 0 ) { $line =~ s/^//; $para = 1; @@ -175,6 +192,8 @@ sub proc_txt { } } + # inline docbook + # ulink # if ($line =~ /\[\[/) { @@ -230,6 +249,7 @@ sub close3 { &closeorderedlist; &closelist; &closepara; + &closeqandaset; if ($level3 == 1) { $buf .= "\n"; $level3 = 0; @@ -240,6 +260,7 @@ sub closenonsect { &closepara; &closeorderedlist; &closelist; + &closeqandaentry; } sub closeorderedlist { @@ -268,6 +289,21 @@ sub closelistitem { } } +sub closeqandaentry { + if ($qandaentry == 1) { + $buf .= "\n"; + $qandaentry = 0; + } +} + +sub closeqandaset { + &closeqandaentry; + if ($qandaset == 1) { + $buf .= "\n"; + $qandaset = 0; + } +} + sub closepara { if ($para == 1) { $buf .= "\n"; @@ -281,7 +317,7 @@ sub splittitle { $title = $line; $id = ""; if ($line =~ /\|/) { - $title =~ s/\|\w+//; + $title =~ s/\|.+//; $id = $line; $id =~ s/^.+\|//; }