Improved script

This commit is contained in:
meles5 2015-10-27 22:24:28 +01:00
parent 8004508b3c
commit 8de3f8d487

View File

@ -110,11 +110,14 @@ class AsciiDoc:
modified_src = os.path.join(self._tempdir, src_basename)
shutil.copy('www/header.asciidoc', modified_src)
with open(modified_src, 'a', encoding='utf-8') as outfp:
final_source = ""
with open(src, 'r', encoding='utf-8') as infp:
outfp.write('\n')
final_source += "\n\n"
hidden = False
replaced_title = False
found_title = False
title = ""
last_line = ""
for line in infp:
if line.strip() == '// QUTE_WEB_HIDE':
@ -124,16 +127,32 @@ class AsciiDoc:
assert hidden
hidden = False
if not replaced_title:
if not found_title:
if re.match(r'^=+$', line):
line = line.replace('=', '-')
replaced_title = True
found_title = True
title = last_line + "=" * (len(last_line) - 1)
elif re.match(r'^= .+', line):
line = '==' + line[1:]
replaced_title = True
found_title = True
title = last_line + "=" * (len(last_line) - 1)
if not hidden:
outfp.write(line)
final_source += line.replace(".asciidoc[", ".html[")
last_line = line
with open(modified_src, 'a', encoding='utf-8') as outfp:
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')