summaryrefslogtreecommitdiff
path: root/scripts/asciidoc2html.py
diff options
context:
space:
mode:
authormeles5 <meles5@web.de>2015-10-27 22:24:28 +0100
committermeles5 <meles5@web.de>2015-10-27 22:24:28 +0100
commit8de3f8d487062e2f10638d6dd82c2002e0ec15d2 (patch)
tree87ad8dc7f2658fc3a3ba20d71ed52d517a55eb5b /scripts/asciidoc2html.py
parent8004508b3c6690e708a19a932c736b685c0d4708 (diff)
downloadqutebrowser-8de3f8d487062e2f10638d6dd82c2002e0ec15d2.tar.gz
qutebrowser-8de3f8d487062e2f10638d6dd82c2002e0ec15d2.zip
Improved script
Diffstat (limited to 'scripts/asciidoc2html.py')
-rwxr-xr-xscripts/asciidoc2html.py65
1 files changed, 42 insertions, 23 deletions
diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py
index e6cffae51..a34b1e819 100755
--- a/scripts/asciidoc2html.py
+++ b/scripts/asciidoc2html.py
@@ -110,30 +110,49 @@ class AsciiDoc:
modified_src = os.path.join(self._tempdir, src_basename)
shutil.copy('www/header.asciidoc', modified_src)
+ final_source = ""
+
+ with open(src, 'r', encoding='utf-8') as infp:
+ final_source += "\n\n"
+ hidden = False
+ found_title = False
+ title = ""
+ last_line = ""
+
+ for line in infp:
+ if line.strip() == '// QUTE_WEB_HIDE':
+ assert not hidden
+ hidden = True
+ elif line.strip() == '// QUTE_WEB_HIDE_END':
+ assert hidden
+ hidden = False
+
+ if not found_title:
+ if re.match(r'^=+$', line):
+ line = line.replace('=', '-')
+ found_title = True
+ title = last_line + "=" * (len(last_line) - 1)
+ elif re.match(r'^= .+', line):
+ line = '==' + line[1:]
+ found_title = True
+ title = last_line + "=" * (len(last_line) - 1)
+
+ if not hidden:
+ final_source += line.replace(".asciidoc[", ".html[")
+ last_line = line
+
with open(modified_src, 'a', encoding='utf-8') as outfp:
- with open(src, 'r', encoding='utf-8') as infp:
- outfp.write('\n')
- hidden = False
- replaced_title = False
-
- for line in infp:
- if line.strip() == '// QUTE_WEB_HIDE':
- assert not hidden
- hidden = True
- elif line.strip() == '// QUTE_WEB_HIDE_END':
- assert hidden
- hidden = False
-
- if not replaced_title:
- if re.match(r'^=+$', line):
- line = line.replace('=', '-')
- replaced_title = True
- elif re.match(r'^= .+', line):
- line = '==' + line[1:]
- replaced_title = True
-
- if not hidden:
- outfp.write(line)
+ outfp.write(final_source)
+
+ current = open(modified_src)
+ current_lines = current.read()
+ current.close()
+
+ final_version = open(modified_src, "w+")
+ final_version.write(title + "\n\n" + current_lines)
+ final_version.close()
+
+ print(title)
self.call(modified_src, dst, '--theme=qute')