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. Custom Markdown parser with Typst output format bridges this gap.
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.