Improved script

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

View File

@ -110,30 +110,49 @@ class AsciiDoc:
modified_src = os.path.join(self._tempdir, src_basename) modified_src = os.path.join(self._tempdir, src_basename)
shutil.copy('www/header.asciidoc', modified_src) 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(modified_src, 'a', encoding='utf-8') as outfp:
with open(src, 'r', encoding='utf-8') as infp: outfp.write(final_source)
outfp.write('\n')
hidden = False
replaced_title = False
for line in infp: current = open(modified_src)
if line.strip() == '// QUTE_WEB_HIDE': current_lines = current.read()
assert not hidden current.close()
hidden = True
elif line.strip() == '// QUTE_WEB_HIDE_END':
assert hidden
hidden = False
if not replaced_title: final_version = open(modified_src, "w+")
if re.match(r'^=+$', line): final_version.write(title + "\n\n" + current_lines)
line = line.replace('=', '-') final_version.close()
replaced_title = True
elif re.match(r'^= .+', line):
line = '==' + line[1:]
replaced_title = True
if not hidden: print(title)
outfp.write(line)
self.call(modified_src, dst, '--theme=qute') self.call(modified_src, dst, '--theme=qute')