From 63280b63a8ed4496619eea3a9a1c80f54458709e Mon Sep 17 00:00:00 2001 From: Kyle King Date: Wed, 30 Oct 2024 06:00:02 -0400 Subject: [PATCH 1/6] test: add red test --- tests/format/fixtures/text.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/format/fixtures/text.md b/tests/format/fixtures/text.md index 141e93b..750ecde 100644 --- a/tests/format/fixtures/text.md +++ b/tests/format/fixtures/text.md @@ -1650,3 +1650,38 @@ Support inline bulleted code (https://github.com/KyleKing/mdformat-mkdocs/issues iex (new-object net.webclient).DownloadString('https://get.scoop.sh') ``` . + +pymdown snippets (https://github.com/KyleKing/mdformat-mkdocs/issues/34) +. +# Snippets + +--8<-- "filename.ext" + +--8<-- "; skip.md" + + +--8<-- +filename.md +filename.log +--8<-- + +Content of file A. + +Content of file B. +. +# Snippets + +--8<-- "filename.ext" + +--8<-- "; skip.md" + + +--8<-- +filename.md +filename.log +--8<-- + +Content of file A. + +Content of file B. +. From 4e09a7fce15c6b7fc8b3210dd9b80c17dca11281 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Mon, 16 Dec 2024 06:17:13 -0500 Subject: [PATCH 2/6] fix(#34): do not break pymd snippets --- mdformat_mkdocs/mdit_plugins/__init__.py | 3 + mdformat_mkdocs/mdit_plugins/_pymd_snippet.py | 72 +++++++++++++++++++ mdformat_mkdocs/plugin.py | 6 +- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 mdformat_mkdocs/mdit_plugins/_pymd_snippet.py diff --git a/mdformat_mkdocs/mdit_plugins/__init__.py b/mdformat_mkdocs/mdit_plugins/__init__.py index 565d1d9..2fec958 100644 --- a/mdformat_mkdocs/mdit_plugins/__init__.py +++ b/mdformat_mkdocs/mdit_plugins/__init__.py @@ -15,6 +15,7 @@ mkdocstrings_crossreference_plugin, ) from ._pymd_abbreviations import PYMD_ABBREVIATIONS_PREFIX, pymd_abbreviations_plugin +from ._pymd_snippet import PYMD_SNIPPET_PREFIX, pymd_snippet_plugin from ._python_markdown_admon import python_markdown_admon_plugin __all__ = ( @@ -24,10 +25,12 @@ "MKDOCSTRINGS_CROSSREFERENCE_PREFIX", "MKDOCSTRINGS_HEADING_AUTOREFS_PREFIX", "PYMD_ABBREVIATIONS_PREFIX", + "PYMD_SNIPPET_PREFIX", "material_admon_plugin", "material_content_tabs_plugin", "mkdocstrings_autorefs_plugin", "mkdocstrings_crossreference_plugin", "pymd_abbreviations_plugin", + "pymd_snippet_plugin", "python_markdown_admon_plugin", ) diff --git a/mdformat_mkdocs/mdit_plugins/_pymd_snippet.py b/mdformat_mkdocs/mdit_plugins/_pymd_snippet.py new file mode 100644 index 0000000..559ad6e --- /dev/null +++ b/mdformat_mkdocs/mdit_plugins/_pymd_snippet.py @@ -0,0 +1,72 @@ +"""Python-Markdown Snippets. + +WARNING: matches only the "scissors" portion, leaving the rest unparsed + +```md +--8<-- ... +``` + +Docs: + +""" + +from __future__ import annotations + +import re + +from markdown_it import MarkdownIt +from markdown_it.rules_block import StateBlock +from mdit_py_plugins.utils import is_code_block + +from mdformat_mkdocs._synced.admon_factories import new_token + +# _SNIPPET_MARKER = "--8<--" +_ABBREVIATION_PATTERN = re.compile( + r"--8<-- (?P