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
+ outfp.write(final_source)
- 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
+ current = open(modified_src)
+ current_lines = current.read()
+ current.close()
- 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
+ final_version = open(modified_src, "w+")
+ final_version.write(title + "\n\n" + current_lines)
+ final_version.close()
- if not hidden:
- outfp.write(line)
+ print(title)
self.call(modified_src, dst, '--theme=qute')