3 # This script is written intended as a living, evolving tooling
4 # to fix oopsies within the docbook documentation.
6 # This is *not* a formatter. It, instead, handles some known cases
7 # where something bad happened, and fixing it manually is tedious.
9 # Read the code to see the different cases it handles.
11 # ALWAYS `make format` after fixing with this!
12 # ALWAYS read the changes, this tool isn't yet proven to be always right.
14 require "rexml/document"
17 if ARGV.length < 1 then
18 $stderr.puts "Needs a filename."
23 doc = Document.new(File.open(filename))
27 # Fixing varnames having a sibling element without spacing.
28 # This is to fix an initial `xmlformat` issue where `term`
29 # would mangle as spaces.
32 # <term><varname>types.separatedString</varname><replaceable>sep</replaceable> <----
36 # Generates: types.separatedStringsep
39 # <varlistentry xml:id='fun-makeWrapper'>
41 # <function>makeWrapper</function><replaceable>executable</replaceable><replaceable>wrapperfile</replaceable><replaceable>args</replaceable> <----
44 # Generates: makeWrapperexecutablewrapperfileargs
48 # <option>--option</option><replaceable>name</replaceable><replaceable>value</replaceable> <-----
51 # Generates: --optionnamevalue
53 doc.elements.each("//varlistentry/term") do |term|
54 ["varname", "function", "option", "replaceable"].each do |prev_name|
55 term.elements.each(prev_name) do |el|
56 if el.next_element and
57 el.next_element.name == "replaceable" and
58 el.next_sibling_node.class == Element
61 term.insert_after(el, Text.new(" "))
70 # <command>nixos-option</command>
72 # <option>-I</option><replaceable>path</replaceable> <------
77 doc.elements.each("//cmdsynopsis/arg") do |term|
78 ["option", "replaceable"].each do |prev_name|
79 term.elements.each(prev_name) do |el|
80 if el.next_element and
81 el.next_element.name == "replaceable" and
82 el.next_sibling_node.class == Element
85 term.insert_after(el, Text.new(" "))
93 # <group choice='req'>
94 # <arg choice='plain'>
95 # <option>--profile-name</option>
98 # <arg choice='plain'>
101 # </group><replaceable>name</replaceable> <----
104 # Generates: [{--profile-name | -p }name]
106 doc.elements.each("//cmdsynopsis/arg") do |term|
107 ["group"].each do |prev_name|
108 term.elements.each(prev_name) do |el|
109 if el.next_element and
110 el.next_element.name == "replaceable" and
111 el.next_sibling_node.class == Element
114 term.insert_after(el, Text.new(" "))
122 doc.context[:attribute_quote] = :quote
123 doc.write(output: File.open(filename, "w"))