scripts for converting to HTML
[gitmagic/dustin.git] / wiki2xml
blobad8482b8caf0addfdd55f0a8f5ce9a32c92754d0
1 #!/usr/bin/gawk -f
2 # Converts small subset of MediaWiki to DocBook
3 # Ben Lynn
5 func close_para() {
6 in_para = 0
7 print "</para>"
10 func open_section(tag) {
11 stack[stack_i] = tag
12 stack_i = stack_i + 1
13 print "<"tag">"
16 func close_section() {
17 if (in_para) close_para();
18 stack_i = stack_i - 1
19 print "</"stack[stack_i]">"
22 func close_until(i) {
23 while (stack_i > i) {
24 close_section()
28 BEGIN {
29 stack_i = 0
30 open_section("chapter")
33 /^ *$/ {
34 if (in_para) close_para();
35 next
38 /^ *==.*==$/ {
39 gsub(" *== *","")
40 close_until(1)
41 open_section("section")
42 print "<title>"$0"</title>"
43 next
46 /^ *=.*=$/ {
47 gsub(" *= *","")
48 print "<title>"$0"</title>"
49 next
53 if (!in_para) {
54 print "<para>"
55 in_para = 1
57 print $0
60 END {
61 while (stack_i > 0) {
62 close_section()