Many minor edits
[gitmagic/gitmagic.git] / wiki2xml
blobc6abb91a677602814eebd700d160acf341ed7ee5
1 #!/usr/bin/gawk -f
2 # Converts variant of MediaWiki to DocBook
3 # Ben Lynn
5 func open_section(tag) {
6 stack[stack_i] = tag
7 stack_i = stack_i + 1
8 print "<"tag">"
11 func close_section() {
12 close_block();
13 stack_i = stack_i - 1
14 print "</"stack[stack_i]">"
17 func close_until(i) {
18 close_block()
19 while (stack_i > i) {
20 close_section()
24 func close_block() {
25 if (block_state != "") {
26 print "</"block_state">"
27 block_state = ""
31 func in_block(s) {
32 if (block_state != s) {
33 close_block()
34 print "<"s">"
35 block_state = s
39 BEGIN {
40 stack_i = 0
43 /^ *$/ {
44 close_block()
45 next
48 /^ / {
49 in_block("screen")
50 print $0
51 next
54 /"/ {
55 while (match($0, "\"")) {
56 sub("\"", "\\&#8220;")
57 sub("\"", "\\&#8221;")
61 /''/ {
62 while (match($0, "''")) {
63 sub("''", "<emphasis>")
64 sub("''", "</emphasis>")
68 /^ *===.*===$/ {
69 gsub(" *=== *","")
70 close_until(2)
71 open_section("section")
72 print "<title>"$0"</title>"
73 next
76 /^ *==.*==$/ {
77 gsub(" *== *","")
78 close_until(1)
79 open_section("section")
80 print "<title>"$0"</title>"
81 next
84 /^ *=.*=$/ {
85 gsub(" *= *","")
86 close_until(0)
87 open_section("chapter")
88 print "<title>"$0"</title>"
89 next
92 /\[\[/ {
93 gsub("\\[\\[", "<ulink url=\"")
94 gsub("]\\[", "\">")
95 gsub("]]", "</ulink>")
99 in_block("para")
100 print $0
103 END {
104 close_until(0)