minor edits
[gitmagic/gitmagic.git] / wiki2xml
blobb696e4d30b3d2c754642c9cd83e578f2ba544edc
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
52 /\[\[/ {
53 gsub("\\[\\[", "<ulink url=\"")
54 gsub("]\\[", "\">")
55 gsub("]]", "</ulink>")
56 print $0
57 next
61 if (!in_para) {
62 print "<para>"
63 in_para = 1
65 print $0
68 END {
69 while (stack_i > 0) {
70 close_section()