Merge pull request #1075 from meles5/www

Improved asciidoc2html script
This commit is contained in:
Florian Bruhin 2015-10-30 18:52:14 +01:00
commit d5fe1d3635
2 changed files with 45 additions and 23 deletions

View File

@ -17,6 +17,7 @@ include requirements.txt
include tox.ini
include qutebrowser.py
prune www
prune scripts/dev
exclude scripts/asciidoc2html.py
exclude doc/notes

View File

@ -29,6 +29,7 @@ import glob
import shutil
import tempfile
import argparse
import io
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
@ -76,6 +77,7 @@ class AsciiDoc:
self._build_docs()
def _build_docs(self):
"""Build the documentation by rendering .asciidoc files to .html sites."""
files = self.FILES[:]
for src in glob.glob('doc/help/*.asciidoc'):
name, _ext = os.path.splitext(os.path.basename(src))
@ -85,6 +87,7 @@ class AsciiDoc:
self.call(src, dst)
def _build_website(self):
"""Prepare and build the website."""
theme_file = os.path.abspath(os.path.join('www', 'qute.css'))
shutil.copy(theme_file, self._themedir)
@ -110,35 +113,53 @@ 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:
with open(src, 'r', encoding='utf-8') as infp:
outfp.write('\n')
hidden = False
replaced_title = False
outfp = io.StringIO()
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
with open(modified_src, 'r', encoding='utf-8') as header_file:
header = header_file.read()
header += "\n\n"
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
with open(src, 'r', encoding='utf-8') as infp:
outfp.write("\n\n")
hidden = False
found_title = False
title = ""
last_line = ""
if not hidden:
outfp.write(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:
outfp.write(line.replace(".asciidoc[", ".html["))
last_line = line
current_lines = outfp.getvalue()
outfp.close()
with open(modified_src, 'w+', encoding='utf-8') as final_version:
final_version.write(title + "\n\n" + header + current_lines)
self.call(modified_src, dst, '--theme=qute')
for path in ['icons', 'doc/img']:
shutil.copytree(path, os.path.join(outdir, path))
copy = {'icons': 'icons', 'doc/img': 'doc/img', 'www/media': 'media/'}
for src, dest in copy.items():
shutil.copytree(src, os.path.join(outdir, dest))
os.symlink('README.html', os.path.join(outdir, 'index.html'))