77from bs4 import BeautifulSoup , ResultSet , Tag
88from mkdocs .plugins import BasePlugin
99from mkdocs .structure .pages import Page
10- from mkdocs .config .base import Config
10+ from mkdocs .config .base import Config , load_config
1111from mkdocs .config .config_options import Type as PluginType
1212
1313from .defaults import MARKMAP
2121STYLE_PATH : Path = STATICS_PATH / 'mkdocs-markmap.css'
2222SCRIPT_PATH : Path = STATICS_PATH / 'mkdocs-markmap.js'
2323
24+
2425class MarkmapPlugin (BasePlugin ):
2526 """
2627 Plugin for markmap support
@@ -59,10 +60,15 @@ def markmap(self) -> Dict[str, str]:
5960
6061 def _load_scripts (self , soup : BeautifulSoup , script_base_url : str , js_path : Path ) -> None :
6162 for script_url in self .markmap .values ():
62- try :
63- src : str = script_base_url + download (js_path , script_url )
64- except Exception as e :
65- log .error (f'unable to download script: { script_url } ' )
63+ if script_url .lower ().startswith ("http" ):
64+ try :
65+ src : str = script_base_url + download (js_path , script_url )
66+ except Exception as e :
67+ log .error (f'unable to download script: { script_url } ' )
68+ src = script_url
69+
70+ else :
71+ log .info (f"static script detected: { script_url } " )
6672 src = script_url
6773
6874 script : Tag = soup .new_tag ('script' , src = src , type = 'text/javascript' )
@@ -88,6 +94,7 @@ def on_config(self, config: Config) -> Config:
8894 for key , value in config ['plugins' ].get ('markmap' ).config .items ()
8995 if key in MarkmapExtension .config_defaults
9096 }
97+ self .config ['extra_javascript' ] = config .get ('extra_javascript' , [])
9198
9299 return config
93100
0 commit comments