Skip to content

Commit

Permalink
Fix bug with javascript parameter when local lib (#90)
Browse files Browse the repository at this point in the history
  - Fixed error of incorrect call to javascript library
    (the relative path was not being adapted)
  • Loading branch information
Laurent Franceschetti committed Sep 26, 2023
1 parent 7db460e commit df11b49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ venv.bak/
.ropeproject

# mkdocs documentation
/site
site/

# mypy
.mypy_cache/
11 changes: 8 additions & 3 deletions mermaid2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,23 @@ def on_post_page(self, output_content, config, page, **kwargs):
new_tag = soup.new_tag("script")
js_code = [] # the code lines
if not self.extra_javascript:
javascript = self.javascript.strip()
if not javascript.startswith("http"):
# it is necessary to adapt the link
javascript = os.path.relpath(javascript,
os.path.dirname(page.url))
# if no extra library mentioned,
# add the <SCRIPT> tag needed for mermaid
if self.javascript.endswith('.mjs'):
if javascript.endswith('.mjs'):
# <script type="module">
# import mermaid from ...
new_tag['type'] = "module"
js_code.append('import mermaid from "%s";'
% self.javascript)
% javascript)
else:
# <script src="...">
# generally for self.mermaid_major_version < 10:
new_tag['src'] = self.javascript
new_tag['src'] = javascript
# it's necessary to close and reopen the tag:
soup.body.append(new_tag)
new_tag = soup.new_tag("script")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages


VERSION = '1.1.0'
VERSION = '1.1.1'

# required if you want to run tests
# pip install 'mkdocs-mermaid2-plugin[test]'
Expand Down

0 comments on commit df11b49

Please sign in to comment.