diff --git a/CHANGELOG.md b/CHANGELOG.md index ef7b4fd..0462263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog +## 3.10.3 (2024-08-16) + +### Fix + +* Handled MkDocs path directives in configurations (fixes #103) [Michele Tessaro] + + ## 3.10.2 (2024-08-09) ### Fix diff --git a/plantuml_markdown/plantuml_markdown.py b/plantuml_markdown/plantuml_markdown.py index bce989f..9d50e1e 100644 --- a/plantuml_markdown/plantuml_markdown.py +++ b/plantuml_markdown/plantuml_markdown.py @@ -122,7 +122,7 @@ class PlantUMLPreprocessor(markdown.preprocessors.Preprocessor): (?P=indent)(?P=fence)[ ]*$ ''', re.MULTILINE | re.DOTALL | re.VERBOSE) # (?P[ ]*)(?P(?:~{3}|`{3}))[ ]*(\{?\.?(plant)?uml)[ ]*\n(?P.*?)(?<=\n)(?P=indent)(?P=fence)$ - FENCED_CODE_RE = re.compile(r'(?P(?:~{4,}|`{4,})).*?(?P=fence)', + FENCED_CODE_RE = re.compile(r'(?P(~{4,}|`{4,})).*?(?P=fence)', re.MULTILINE | re.DOTALL | re.VERBOSE) def __init__(self, md): @@ -146,9 +146,12 @@ def run(self, lines: List[str]) -> List[str]: self._fallback_to_get = bool(self.config['fallback_to_get']) self._base_dir = self.config['base_dir'] - if isinstance(self._base_dir, str): + if not isinstance(self._base_dir, list): self._base_dir = [self._base_dir] + # make sure they are strings (can be DocsDirPlaceholder is !relative is used in mkdocs.yml) + self._base_dir = [str(v) for v in self._base_dir] + self._config_path = self.config['config'] if self.config['config']: diff --git a/setup.py b/setup.py index b102465..4489e93 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setuptools.setup( name="plantuml-markdown", - version="3.10.2", + version="3.10.3", author="Michele Tessaro", author_email="michele.tessaro.tex@gmail.com", description="A PlantUML plugin for Markdown", diff --git a/test-requirements.txt b/test-requirements.txt index 86fe314..ef6b22b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,5 @@ httpservermock +mkdocs mock nose2 pymdown-extensions diff --git a/test/data/docs/example.puml b/test/data/docs/example.puml new file mode 100644 index 0000000..8acbb1f --- /dev/null +++ b/test/data/docs/example.puml @@ -0,0 +1,5 @@ +@startuml + +A -> B + +@enduml diff --git a/test/data/mkdocs.yml b/test/data/mkdocs.yml new file mode 100644 index 0000000..90e850a --- /dev/null +++ b/test/data/mkdocs.yml @@ -0,0 +1,6 @@ +site_name: MkDocs test + +docs_dir: data/docs +markdown_extensions: + - plantuml_markdown: + base_dir: !relative $docs_dir diff --git a/test/test_plantuml.py b/test/test_plantuml.py index 75ca467..70765ed 100644 --- a/test/test_plantuml.py +++ b/test/test_plantuml.py @@ -9,6 +9,8 @@ from unittest import TestCase, SkipTest from httpservermock import MethodName, MockHTTPResponse, ServedBaseHTTPServerMock +from mkdocs.config.defaults import MkDocsConfig +from mkdocs.utils.yaml import DocsDirPlaceholder class PlantumlTest(TestCase): @@ -610,6 +612,42 @@ def test_source(self): r"\s+`-+'\s+`-'\n" r'', re.DOTALL)) + def test_source_mkdocs(self): + """ + Test that source works with MkDocs config directives like `!relative` + """ + include_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') + mkdocs_config = MkDocsConfig() + # load the MkDocs config + with open(os.path.join(include_path, 'mkdocs.yml'), 'r') as f: + mkdocs_config.load_file(f) + + configs = { + 'plantuml_markdown': { + 'base_dir': [ + '/tmp', # fake path where file to include is not present + DocsDirPlaceholder(mkdocs_config), # passes the `!relative $docs_dir` + ] + } + } + self.md = markdown.Markdown(extensions=['plantuml_markdown'], + extension_configs=configs) + + text = self.text_builder.diagram(" ")\ + .source("example.puml")\ + .format("txt")\ + .build() + self.assertRegex(self.md.convert(text), + re.compile(r'
\s+,-+\.\s+,-\.\n'
+                                    r'\s+\|.*\|\s+\|B\|'
+                                    r'.*'
+                                    r'\s+\|.*\|\s+'
+                                    r'\s+\|\s*-+>\|\s+'
+                                    r'.*'
+                                    r'\s+\|.*\|\s+\|B\|'
+                                    r'.*'
+                                    r'
', re.DOTALL)) + def _server_render(self, filename: str, text: Union[str, Callable[[str], str]], expected='
A -> B -> C
', server='server'):