markdown_parser ¶
math_pattern = re.compile('(\\$\\$.*?\\$\\$)') module-attribute ¶
md = markdown.core.Markdown(extensions=['admonition']) module-attribute ¶
typst_command_pattern = re.compile('#([A-Za-z][^\\s()\\[]*)(\\([^)]*\\))?(\\[[^\\]]*\\])?') module-attribute ¶
escape_typst_characters(string) ¶
Escape Typst special characters while preserving Typst commands and math.
Why
User content may contain Typst special characters like #, $, [ that would break compilation. Escaping prevents interpretation as commands. Existing Typst commands and math must remain unescaped.
Parameters:
-
string(str) –Text to escape.
Returns:
-
str–Escaped string safe for Typst.
Source code in src/rendercv/renderer/templater/markdown_parser.py
markdown_to_html(markdown_string) ¶
Convert Markdown string to HTML using python-markdown library.
Parameters:
-
markdown_string(str) –Markdown content.
Returns:
-
str–HTML-formatted string.
Source code in src/rendercv/renderer/templater/markdown_parser.py
markdown_to_typst(markdown_string) ¶
Convert Markdown string to Typst markup.
Why
Users write content in Markdown for readability. Typst compilation requires Typst markup. Lines are processed independently to prevent emphasis markers on adjacent lines from interacting in the Markdown parser (single-newline-separated lines form one paragraph in Markdown, causing cross-line marker interference). Admonition blocks are kept together since they span multiple lines by design.
Parameters:
-
markdown_string(str) –Markdown content.
Returns:
-
str–Typst-formatted string.
Source code in src/rendercv/renderer/templater/markdown_parser.py
to_typst_string(elem) ¶
Recursively convert XML Element tree to Typst markup string.
Why
Python Markdown library outputs XML Element tree. Typst requires its own markup syntax for bold, italic, links, etc. Recursive traversal converts entire element tree including nested formatting.
Parameters:
-
elem(Element) –XML Element from Markdown parser.
Returns:
-
str–Typst-formatted string.