Second chapter
[gitmagic.git] / wiki2xml
blob00565d1bd0f2cbd9c8c0cf8688121cfe8ce79630
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 while (stack_i > i) {
19 close_section()
23 func close_block() {
24 if (block_state != "") {
25 print "</"block_state">"
26 block_state = ""
30 func in_block(s) {
31 if (block_state != s) {
32 close_block()
33 print "<"s">"
34 block_state = s
38 BEGIN {
39 stack_i = 0
40 open_section("chapter")
43 /^ *$/ {
44 close_block()
45 next
48 /^ *==.*==$/ {
49 gsub(" *== *","")
50 close_until(1)
51 open_section("section")
52 print "<title>"$0"</title>"
53 next
56 /^ *=.*=$/ {
57 gsub(" *= *","")
58 print "<title>"$0"</title>"
59 next
62 /\[\[/ {
63 gsub("\\[\\[", "<ulink url=\"")
64 gsub("]\\[", "\">")
65 gsub("]]", "</ulink>")
66 print $0
67 next
70 /^ / {
71 in_block("screen")
72 print $0
73 next
77 in_block("para")
78 print $0
81 END {
82 while (stack_i > 0) {
83 close_section()