Improved code style
This commit is contained in:
parent
8600acddb1
commit
f807842a52
@ -29,6 +29,7 @@ import glob
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import argparse
|
import argparse
|
||||||
|
import io
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
||||||
|
|
||||||
@ -110,41 +111,45 @@ 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)
|
||||||
|
|
||||||
with open(modified_src, 'a', encoding='utf-8') as outfp:
|
outfp = io.StringIO()
|
||||||
with open(src, 'r', encoding='utf-8') as infp:
|
|
||||||
outfp.write("\n\n")
|
|
||||||
hidden = False
|
|
||||||
found_title = False
|
|
||||||
title = ""
|
|
||||||
last_line = ""
|
|
||||||
|
|
||||||
for line in infp:
|
with open(modified_src) as header_file:
|
||||||
if line.strip() == '// QUTE_WEB_HIDE':
|
header = header_file.read()
|
||||||
assert not hidden
|
header += "\n\n"
|
||||||
hidden = True
|
|
||||||
elif line.strip() == '// QUTE_WEB_HIDE_END':
|
|
||||||
assert hidden
|
|
||||||
hidden = False
|
|
||||||
|
|
||||||
if not found_title:
|
with open(src, 'r', encoding='utf-8') as infp:
|
||||||
if re.match(r'^=+$', line):
|
outfp.write("\n\n")
|
||||||
line = line.replace('=', '-')
|
hidden = False
|
||||||
found_title = True
|
found_title = False
|
||||||
title = last_line + "=" * (len(last_line) - 1)
|
title = ""
|
||||||
elif re.match(r'^= .+', line):
|
last_line = ""
|
||||||
line = '==' + line[1:]
|
|
||||||
found_title = True
|
|
||||||
title = last_line + "=" * (len(last_line) - 1)
|
|
||||||
|
|
||||||
if not hidden:
|
for line in infp:
|
||||||
outfp.write(line.replace(".asciidoc[", ".html["))
|
if line.strip() == '// QUTE_WEB_HIDE':
|
||||||
last_line = line
|
assert not hidden
|
||||||
|
hidden = True
|
||||||
|
elif line.strip() == '// QUTE_WEB_HIDE_END':
|
||||||
|
assert hidden
|
||||||
|
hidden = False
|
||||||
|
|
||||||
with open(modified_src) as current:
|
if not found_title:
|
||||||
current_lines = current.read()
|
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:
|
||||||
|
outfp.write(line.replace(".asciidoc[", ".html["))
|
||||||
|
last_line = line
|
||||||
|
|
||||||
|
current_lines = outfp.getvalue()
|
||||||
|
|
||||||
with open(modified_src, "w+") as final_version:
|
with open(modified_src, "w+") as final_version:
|
||||||
final_version.write(title + "\n\n" + current_lines)
|
final_version.write(title + "\n\n" + header + current_lines)
|
||||||
|
|
||||||
self.call(modified_src, dst, '--theme=qute')
|
self.call(modified_src, dst, '--theme=qute')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user