Correction on effects of git-checkout
[gitmagic.git] / wiki2xml
blob95843ee1e2968c4e18cb7eeec0f65ae527d71254
1 #!/usr/bin/gawk -f
2 # Converts small subset 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 gsub(" *=== *","")
50 close_until(2)
51 open_section("section")
52 print "<title>"$0"</title>"
53 next
56 /^ *==.*==$/ {
57 gsub(" *== *","")
58 close_until(1)
59 open_section("section")
60 print "<title>"$0"</title>"
61 next
64 /^ *=.*=$/ {
65 gsub(" *= *","")
66 close_until(0)
67 open_section("chapter")
68 print "<title>"$0"</title>"
69 next
72 /\[\[/ {
73 gsub("\\[\\[", "<ulink url=\"")
74 gsub("]\\[", "\">")
75 gsub("]]", "</ulink>")
78 /^ / {
79 in_block("screen")
80 print $0
81 next
85 in_block("para")
86 print $0
89 END {
90 close_until(0)