LP#
1848524: AsciiDoc HEADING CONVERSION
This commit changes all headings from two-line style to prefix/suffix
style. (For now, we're only doing this in the docs using Antora.) Example:
Heading 1
=========
becomes
= Heading 1 =
This conversion makes it much easier to adjust the heading levels of
several files which were previously included using the 'leveloffset'
command.
NOTE: Only the prefix is required, but we felt the suffix improves
readability of the source.
Below is the python script I used to do the conversion. It is slightly
modified from a script used by ___ here:
https://github.com/JanusGraph/janusgraph/pull/115/commits/
dc67ce73c08e79fa65b30bc8280861056070c573
Here's my source:
import re
import sys
def main(argv):
#http://asciidoctor.org/docs/asciidoc-recommended-practices/#section-titles
patterns = [
(re.compile('^=+$'), '='),
(re.compile('^-+$'), '=='),
(re.compile('^~+$'), '==='),
(re.compile('^\^+$'), '===='),
(re.compile('^\++$'), '====='),
]
with open(argv[1], 'r') as input_file:
prev_line = None
curr_line = None
for line in input_file.readlines():
prev_line = curr_line
curr_line = line
if prev_line is None:
continue
for pattern, heading in patterns:
if pattern.match(curr_line) and len(prev_line) == len(curr_line):
# remove newline so we can append suffix to heading
prev_line = prev_line.rstrip()
sys.stdout.write('%s %s %s\n' % (heading, prev_line, heading))
prev_line = None
curr_line = None
break
if prev_line is not None:
sys.stdout.write(prev_line)
# end for
if curr_line is not None:
sys.stdout.write(curr_line)
# end with
if __name__ == '__main__':
main(sys.argv)
Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>