From 4a30e5a7d2939806bfaca8022423e89190f2667a Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Wed, 18 Dec 2024 15:47:50 +0100 Subject: [PATCH] Publish documentation as HTML rather than AsciiDoc/Markdown --- dodo.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/dodo.py b/dodo.py index 48aab06..92482cf 100644 --- a/dodo.py +++ b/dodo.py @@ -9,6 +9,7 @@ from enum import Enum from shutil import rmtree, copy, copytree, make_archive import platform import tomllib +import re root_dir = Path(__file__).parent rhubarb_dir = root_dir / 'rhubarb' @@ -128,9 +129,9 @@ def task_package(): def collect_artifacts(): # Misc. files - copy(root_dir / 'README.adoc', tree_dir) - copy(root_dir / 'LICENSE.md', tree_dir) - copy(root_dir / 'CHANGELOG.md', tree_dir) + asciidoc_to_html(root_dir / 'README.adoc', tree_dir / 'README.html') + markdown_to_html(root_dir / 'LICENSE.md', tree_dir / 'LICENSE.html') + markdown_to_html(root_dir / 'CHANGELOG.md', tree_dir / 'CHANGELOG.html') copytree(root_dir / 'img', tree_dir / 'img') # Rhubarb @@ -142,20 +143,20 @@ def task_package(): src = extras_dir / 'adobe-after-effects' dst_extras_dir = ensure_dir(tree_dir / 'extras') dst = ensure_dir(dst_extras_dir / 'adobe-after-effects') - copy(src / 'README.adoc', dst) + asciidoc_to_html(src / 'README.adoc', dst / 'README.html') copy(src / 'Rhubarb Lip Sync.jsx', dst) # Rhubarb for Spine src = extras_dir / 'esoteric-software-spine' dst = ensure_dir(dst_extras_dir / 'esoteric-software-spine') - copy(src / 'README.adoc', dst) + asciidoc_to_html(src / 'README.adoc', dst / 'README.html') for file in (src / 'build' / 'libs').iterdir(): copy(file, dst) # Magix Vegas src = extras_dir / 'magix-vegas' dst = ensure_dir(dst_extras_dir / 'magix-vegas') - copy(src / 'README.adoc', dst) + asciidoc_to_html(src / 'README.adoc', dst / 'README.html') copy(src / 'Debug Rhubarb.cs', dst) copy(src / 'Debug Rhubarb.cs.config', dst) copy(src / 'Import Rhubarb.cs', dst) @@ -218,6 +219,50 @@ def get_formatter(path: Path) -> Optional[Formatter]: return Formatter.RUFF +def asciidoc_to_html(src: Path, dst: Path): + subprocess.run( + ['deno', 'run', '-A', 'npm:asciidoctor@3.0.0', '-a', 'toc=left', '-o', dst, src], check=True + ) + + +def markdown_to_html(src: Path, dst: Path): + tmp = dst.parent.joinpath(f'{src.stem}-tmp.adoc') + try: + markdown_to_asciidoc(src, tmp) + asciidoc_to_html(tmp, dst) + finally: + tmp.unlink() + + +def markdown_to_asciidoc(src: Path, dst: Path): + """Cheap best-effort heuristics for converting Markdown to AsciiDoc""" + + markup = src.read_text() + + # Convert headings + markup = re.sub('^#+', lambda match: '=' * len(match[0]), markup, flags=re.MULTILINE) + + # Convert italics + markup = re.sub( + r'(? Path: """Makes sure the given directory exists."""