diff --git a/src/dragonglass/dragonglass.py b/src/dragonglass/dragonglass.py index c1a6b3a..12717cd 100644 --- a/src/dragonglass/dragonglass.py +++ b/src/dragonglass/dragonglass.py @@ -7,7 +7,8 @@ from pathlib import Path from .config import Context from .mparse import create_markdown_parser -from .template import create_template_environment +from .style import write_default_stylesheet +from .template import create_template_environment, template_vars from .tree import SourceIndex, generate_list logger = logging.getLogger(__name__) @@ -76,11 +77,13 @@ def main() -> int: if node.is_dir: p.mkdir(exist_ok=True) elif node.is_md: + context.current_node = node tmpl = tenv.get_template(context.get_template_name_for_node(node)) - data = tmpl.render(node.make_vars()) + data = tmpl.render(template_vars(node, context)) with p.open("wt") as f: f.write(data) else: shutil.copyfile(context.source_dir / node.path, p) + write_default_stylesheet(tenv, dest_dir) return 0 diff --git a/src/dragonglass/style.py b/src/dragonglass/style.py new file mode 100644 index 0000000..8e11233 --- /dev/null +++ b/src/dragonglass/style.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from jinja2 import Environment + +STYLESHEET_NAME = "dragonglass.css" +STYLESHEET_DATA = """/* Dragonglass default CSS file - ensure all generated HTML pages reference this */ +a { + color: #8a5cf5; +} +.invalid-reference { + color: #ad8df8; + text-decoration: underline; + text-decoration-color: #e6ddfd; +} +ins { + background-color: #ffec99; + text-decoration: none; +} +""" + + +def write_default_stylesheet(tenv: Environment, dest_dir: Path) -> None: + to_file = dest_dir / STYLESHEET_NAME + tmpl = tenv.from_string(STYLESHEET_DATA) + data = tmpl.render({}) + with to_file.open("wt") as f: + f.write(data) diff --git a/src/dragonglass/template.py b/src/dragonglass/template.py index 83a65b3..a0c49d5 100644 --- a/src/dragonglass/template.py +++ b/src/dragonglass/template.py @@ -1,13 +1,18 @@ #!/usr/bin/env python3 from jinja2 import Environment, BaseLoader, ChoiceLoader, FunctionLoader, FileSystemLoader +from typing import Any +from urllib.parse import quote as urlquote from .config import Context, DEFAULT_TEMPLATE_NAME +from .style import STYLESHEET_NAME +from .tree import SourceNode DEFAULT_TEMPLATE = """