Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mermaid support #750

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pretext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

VERSION = get_version("pretext", Path(__file__).parent.parent)

CORE_COMMIT = "8e9aac01da8fdab44c6c9ded4f30d9d7227d015b"
CORE_COMMIT = "ed4e9d94a75b5b728aca2eb06dfde3f1595ab783"


def activate() -> None:
Expand Down
14 changes: 14 additions & 0 deletions pretext/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"codelens",
"datafile",
"interactive",
"mermaid",
],
"latex": [
"webwork",
Expand All @@ -32,6 +33,7 @@
"codelens",
"datafile",
"interactive",
"mermaid",
],
"epub": [
"webwork",
Expand All @@ -42,6 +44,7 @@
"codelens",
"datafile",
"interactive",
"mermaid",
],
"kindle": [
"webwork",
Expand All @@ -52,6 +55,7 @@
"codelens",
"datafile",
"interactive",
"mermaid",
],
"braille": [
"webwork",
Expand All @@ -62,6 +66,7 @@
"codelens",
"datafile",
"interactive",
"mermaid",
],
"webwork": [
"webwork",
Expand All @@ -75,6 +80,7 @@
"codelens",
"datafile",
"interactive",
"mermaid",
],
}

Expand All @@ -87,6 +93,7 @@
"codelens": ".//program[@interactive = 'codelens']",
"datafile": ".//datafile",
"interactive": ".//interactive",
"mermaid": ".//mermaid",
}
ASSETS = ["ALL"] + list(ASSET_TO_XPATH.keys())

Expand All @@ -99,18 +106,21 @@
"interactive": ["preview", "qrcode"],
"codelens": ["trace"],
"datafile": ["datafile"],
"mermaid": ["mermaid"],
}

ASSET_FORMATS: t.Dict[str, t.Dict[str, t.List[str]]] = {
"pdf": {
"asymptote": ["pdf"],
"latex-image": [],
"sageplot": ["pdf", "png"],
"mermaid": ["png"],
},
"latex": {
"asymptote": ["pdf"],
"latex-image": [],
"sageplot": ["pdf", "png"],
"mermaid": ["png"],
},
"html": {
"asymptote": ["html"],
Expand All @@ -126,21 +136,25 @@
"asymptote": ["svg"],
"latex-image": ["svg"],
"sageplot": ["svg"],
"mermaid": ["png"],
},
"kindle": {
"asymptote": ["png"],
"latex-image": ["png"],
"sageplot": ["png"],
"mermaid": ["png"],
},
"braille": {
"asymptote": ["all"],
"latex-image": ["all"],
"sageplot": ["all"],
"mermaid": ["png"],
},
"custom": {
"asymptote": ["all"],
"latex-image": ["all"],
"sageplot": ["all"],
"mermaid": ["png"],
},
}

Expand Down
14 changes: 14 additions & 0 deletions pretext/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,20 @@ def generate_assets(
log.debug(e, exc_info=True)
# youtube also requires the play button.
self.ensure_play_button()
if "mermaid" in assets_to_generate:
for id in assets_to_generate["mermaid"]:
try:
core.mermaid_images(
xml_source=self.source_abspath(),
pub_file=self.publication_abspath().as_posix(),
stringparams=stringparams_copy,
xmlid_root=id,
dest_dir=self.generated_dir_abspath() / "mermaid",
)
successful_assets.append(("mermaid", id))
except Exception as e:
log.error(f"Unable to generate some mermaid images: \n{e}")
log.debug(e, exc_info=True)
if "codelens" in assets_to_generate:
for id in assets_to_generate["codelens"]:
try:
Expand Down
1 change: 1 addition & 0 deletions pretext/project/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Executables(pxml.BaseXmlModel, tag="executables"):
asy: t.Optional[str] = pxml.attr(default=shutil.which("asy"))
# The same applies to Sage.
sage: t.Optional[str] = pxml.attr(default=shutil.which("sage"))
mermaid: str = pxml.attr(default="mmdc")
pdfpng: str = pxml.attr(default="convert")
pdfeps: str = pxml.attr(default="pdftops")
node: str = pxml.attr(default="node")
Expand Down
Loading