Skip to content

Commit

Permalink
#35: Restores static javascript support
Browse files Browse the repository at this point in the history
  • Loading branch information
neatc0der committed Jan 28, 2022
1 parent f6bfc8f commit 98300f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mkdocs_markmap/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PACKAGE_NAME = 'mkdocs_markmap'
PROJECT_NAME = PACKAGE_NAME.replace('_', '-')
PROJECT_VERSION = '2.2.0'
PROJECT_VERSION = '2.2.1'

OWNER = 'neatc0der'
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'
17 changes: 12 additions & 5 deletions mkdocs_markmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bs4 import BeautifulSoup, ResultSet, Tag
from mkdocs.plugins import BasePlugin
from mkdocs.structure.pages import Page
from mkdocs.config.base import Config
from mkdocs.config.base import Config, load_config
from mkdocs.config.config_options import Type as PluginType

from .defaults import MARKMAP
Expand All @@ -21,6 +21,7 @@
STYLE_PATH: Path = STATICS_PATH / 'mkdocs-markmap.css'
SCRIPT_PATH: Path = STATICS_PATH / 'mkdocs-markmap.js'


class MarkmapPlugin(BasePlugin):
"""
Plugin for markmap support
Expand Down Expand Up @@ -59,10 +60,15 @@ def markmap(self) -> Dict[str, str]:

def _load_scripts(self, soup: BeautifulSoup, script_base_url: str, js_path: Path) -> None:
for script_url in self.markmap.values():
try:
src: str = script_base_url + download(js_path, script_url)
except Exception as e:
log.error(f'unable to download script: {script_url}')
if script_url.lower().startswith("http"):
try:
src: str = script_base_url + download(js_path, script_url)
except Exception as e:
log.error(f'unable to download script: {script_url}')
src = script_url

else:
log.info(f"static script detected: {script_url}")
src = script_url

script: Tag = soup.new_tag('script', src=src, type='text/javascript')
Expand All @@ -88,6 +94,7 @@ def on_config(self, config: Config) -> Config:
for key, value in config['plugins'].get('markmap').config.items()
if key in MarkmapExtension.config_defaults
}
self.config['extra_javascript'] = config.get('extra_javascript', [])

return config

Expand Down

0 comments on commit 98300f6

Please sign in to comment.