Skip to content

Commit

Permalink
Merge branch 'release/3.10.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikitex70 committed Aug 16, 2024
2 parents 8eb1265 + e815057 commit 12307f1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions plantuml_markdown/plantuml_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class PlantUMLPreprocessor(markdown.preprocessors.Preprocessor):
(?P=indent)(?P=fence)[ ]*$
''', re.MULTILINE | re.DOTALL | re.VERBOSE)
# (?P<indent>[ ]*)(?P<fence>(?:~{3}|`{3}))[ ]*(\{?\.?(plant)?uml)[ ]*\n(?P<code>.*?)(?<=\n)(?P=indent)(?P=fence)$
FENCED_CODE_RE = re.compile(r'(?P<fence>(?:~{4,}|`{4,})).*?(?P=fence)',
FENCED_CODE_RE = re.compile(r'(?P<fence>(~{4,}|`{4,})).*?(?P=fence)',
re.MULTILINE | re.DOTALL | re.VERBOSE)

def __init__(self, md):
Expand All @@ -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']:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setuptools.setup(
name="plantuml-markdown",
version="3.10.2",
version="3.10.3",
author="Michele Tessaro",
author_email="[email protected]",
description="A PlantUML plugin for Markdown",
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
httpservermock
mkdocs
mock
nose2
pymdown-extensions
5 changes: 5 additions & 0 deletions test/data/docs/example.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@startuml

A -> B

@enduml
6 changes: 6 additions & 0 deletions test/data/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
site_name: MkDocs test

docs_dir: data/docs
markdown_extensions:
- plantuml_markdown:
base_dir: !relative $docs_dir
38 changes: 38 additions & 0 deletions test/test_plantuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -610,6 +612,42 @@ def test_source(self):
r"\s+`-+'\s+`-'\n"
r'</code></pre>', 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'<pre><code class="text">\s+,-+\.\s+,-\.\n'
r'\s+\|.*\|\s+\|B\|'
r'.*'
r'\s+\|.*\|\s+'
r'\s+\|\s*-+&gt;\|\s+'
r'.*'
r'\s+\|.*\|\s+\|B\|'
r'.*'
r'</code></pre>', re.DOTALL))

def _server_render(self, filename: str, text: Union[str, Callable[[str], str]],
expected='<pre><code class="text">A -&gt; B -&gt; C</code></pre>',
server='server'):
Expand Down

0 comments on commit 12307f1

Please sign in to comment.