updated snippets generation for adoc format

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
This commit is contained in:
Nikos Mavrogiannopoulos 2018-01-31 15:14:55 +01:00
parent 372438de0a
commit 818dae6e86

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# Split source code files into XML snippets for inclusion in the
# Split source code files into markdown snippets for inclusion in the
# documentation.
#
# Usage: python split-snippets.py TARGET-ROOT INPUT-FILE...
@ -23,7 +23,7 @@ import sys
target_root = sys.argv[1]
def output_file_name(dirname, basename):
return "{0}/en-US/snippets/{1}-{2}.xml".format(
return "{0}/en-US/snippets/{1}-{2}.adoc".format(
target_root, dirname, basename)
re_open_file = re.compile(
@ -41,19 +41,11 @@ def extension_to_language(path, map={
def write_single_file(path, contents, language):
assert not [ch for ch in language if ch in "<>&\""]
with file(path, "w") as out:
out.write('''<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE programlisting PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
]>
<!-- Automatically generated file. Do not edit. -->
<programlisting language="''' + language + '''">
''')
out.write("\n")
for line in contents:
for ch in line:
if ch in "<>&":
out.write("&#{0};".format(ord(ch)))
else:
out.write(ch)
out.write("</programlisting>\n")
out.write(ch)
out.write("\n")
def write_output(output):
for (outpath, (origpath, contents)) in output.items():