]>
pere.pagekite.me Git - text-madewithcc.git/blob - fixup-docbook.rb
7 raise ArgumentError
, 'Source/destination files not specified' if ARGV.size !
= 2
12 xml
= Nokogiri
::XML(f
)
15 indicators
= %w(! •
# -)
17 print indicators
[level
]
19 print
"\n%s %s\n" % ['*' * (level+
1), what
]
23 def partreplace(xml
, partid
, tag
)
24 xml
.css('part[id=' + partid +
']').each
do |part
|
30 log
0, 'replace article* with book*'
31 xml
.css('articleinfo').each
do |node
|
32 node
.name
= 'bookinfo'
33 node
.first_element_child
.before(<<'XML')
35 <publishername>Gunnar Wolf</publishername>
36 <address><city>Mexico City</city></address>
39 node
.first_element_child
.before(<<'XML')
42 <holder>Creative Commons</holder>
46 xml
.css('article').each
do |node
|
51 log
0, 'change parts to colophon, dedication and chapter'
52 partreplace(xml
, 'colophon', 'colophon')
53 partreplace(xml
, 'dedication', 'dedication')
54 partreplace(xml
, 'foreword', 'chapter')
55 partreplace(xml
, 'introduction', 'chapter')
56 partreplace(xml
, 'bibliography', 'chapter')
57 partreplace(xml
, 'acknowledgments', 'chapter')
59 log
0, 'place part introduction into <partintro>'
60 s
= xml
.xpath("//part/title[text()='The Case Studies']")[0]
62 s
.after('<partintro>')
63 p
= xml
.css('part partintro')[0]
64 s
.parent
.xpath("//part/para").each
do |node
|
69 log
0, 'Writing processed file'
70 # Unable to figure out API way to replace DOCTYPE
71 data = xml
.to_xml().gsub!
(/DOCTYPE article/, 'DOCTYPE book')
72 File
.open(dstfile
, 'w') {|f
| f
.write(data)}