"""Render public Markdown originals to static HTML; --check detects stale pages.""" import argparse import html import re from pathlib import Path import markdown2 ROOT = Path(__file__).resolve().parents[1] PAGES = {'INSTALL.md': 'install.html', 'RELEASE_NOTES.md': 'release-notes.html', 'THIRD_PARTY_NOTICES.md': 'licenses.html', 'LICENSE': 'license.html', 'BENCHMARKS.md': 'benchmarks.html', 'CONNECTORS.md': 'connectors.html', 'docs/legal/PUBLIC_SCOPE.md': 'legal-scope.html'} def render(name): source = (ROOT/name).read_text(encoding='utf-8') # Strip fence language hints so optional Pygments cannot change generated bytes. source = re.sub(r'^```[^\n]+$', '```', source, flags=re.MULTILINE) title = source.splitlines()[0].lstrip('# ').strip() if name != 'LICENSE' else 'Application license — AGPL-3.0-only' body = '
'+html.escape(source)+'
' if name == 'LICENSE' else markdown2.markdown(source, extras=['fenced-code-blocks', 'tables'], safe_mode='escape') for old, new in PAGES.items(): body = body.replace('href="'+old+'"', 'href="'+new+'"') return ('\n' ''+html.escape(title)+'' '
'+body+ '

Download original text

\n') def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--check', action='store_true') args = parser.parse_args() for source, target in PAGES.items(): output = render(source) path = ROOT/target if args.check: if not path.exists() or path.read_text(encoding='utf-8') != output: raise SystemExit('Stale public HTML: '+target) else: path.write_text(output, encoding='utf-8') print('Public HTML pages match Markdown originals:', len(PAGES)) if __name__ == '__main__': main()