From 4b8db948eda5d484d713a3d6ed6a443f86fa0a3c Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sat, 3 Aug 2024 00:21:26 -0600 Subject: [PATCH] added support for fenced code blacks with highlighting --- pyproject.toml | 1 + requirements-dev.lock | 2 ++ requirements.lock | 2 ++ src/dragonglass/mparse.py | 16 ++++++++++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6f9446b..8bbc9cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ dependencies = [ "markdown~=3.6", "markupsafe~=2.1.5", "pyyaml~=6.0.1", + "pygments~=2.18.0", ] readme = "README.md" requires-python = ">= 3.8" diff --git a/requirements-dev.lock b/requirements-dev.lock index 084985e..e150a1d 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -19,6 +19,8 @@ markupsafe==2.1.5 # via jinja2 nodeenv==1.9.1 # via pyright +pygments==2.18.0 + # via dragonglass pyright==1.1.373 pyyaml==6.0.1 # via dragonglass diff --git a/requirements.lock b/requirements.lock index 35fa711..a31f9b2 100644 --- a/requirements.lock +++ b/requirements.lock @@ -17,5 +17,7 @@ markdown==3.6 markupsafe==2.1.5 # via dragonglass # via jinja2 +pygments==2.18.0 + # via dragonglass pyyaml==6.0.1 # via dragonglass diff --git a/src/dragonglass/mparse.py b/src/dragonglass/mparse.py index 96f0a86..9dd215f 100644 --- a/src/dragonglass/mparse.py +++ b/src/dragonglass/mparse.py @@ -503,9 +503,21 @@ def create_markdown_parser(context: Context) -> markdown.Markdown: Returns: markdown.Markdown: The new Markdown parser. """ - return markdown.Markdown(extensions=[MetaStripper(), + extconfig: dict[str, Any] = { + 'codehilite': { + 'linenums': False, + 'guess_lang': False, + 'noclasses': False, + 'use_pygments': True, + 'lang_prefix': 'language' + } + } + return markdown.Markdown(extensions=['fenced_code', + 'codehilite', + MetaStripper(), ObsidianComments(), ObsidianStyleFootnotes(SUPERSCRIPT_TEXT='[{}]', SEPARATOR='-'), ObsidianImages(context), ObsidianLinks(context), - ObsidianInlines()]) + ObsidianInlines()], + extension_configs=extconfig)