refactor: compose export controller with explicit snapshots and task lifecycle
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Explicit rendering inputs shared by the reader, previews and exports."""
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from .document_tree import code_language_for_path, is_code_document
|
||||
from .text_io import DEFAULT_TEXT_PREVIEW_BYTES, read_text_with_fallback
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RenderOptions:
|
||||
theme: str = "light"
|
||||
font_scale: float = 1.0
|
||||
wheel_scroll_speed: float = 1.0
|
||||
document_width_scale: float = 1.0
|
||||
document_font_family: str = ""
|
||||
document_font_size: int = 16
|
||||
document_style_css: str = ""
|
||||
math_engine: str = "katex"
|
||||
|
||||
def kwargs(self) -> dict:
|
||||
return asdict(self)
|
||||
|
||||
|
||||
def render_document(renderer, path: Path, source: str | None, options: RenderOptions) -> str:
|
||||
if is_code_document(path):
|
||||
return renderer.render_code_source(read_text_with_fallback(path, DEFAULT_TEXT_PREVIEW_BYTES), path,
|
||||
language=code_language_for_path(path), **options.kwargs())
|
||||
return renderer.render_source(path.read_text(encoding="utf-8") if source is None else source,
|
||||
path, **options.kwargs())
|
||||
Reference in New Issue
Block a user