4343
4444# Load fullscreen CSS and JavaScript from external files
4545_MODULE_DIR = Path (__file__ ).parent
46- _FULLSCREEN_CSS = (_MODULE_DIR / "fullscreen.css" ).read_text (encoding = "utf-8" )
47- _MERMAID_CSS = (_MODULE_DIR / "default.css" ).read_text (encoding = "utf-8" )
48- _MERMAID_RUN = (_MODULE_DIR / "default.js" ).read_text (encoding = "utf-8" )
46+ _FULLSCREEN_CSS = (_MODULE_DIR / "fullscreen.css.j2 " ).read_text (encoding = "utf-8" )
47+ _MERMAID_CSS = (_MODULE_DIR / "default.css.j2 " ).read_text (encoding = "utf-8" )
48+ _MERMAID_RUN = (_MODULE_DIR / "default.js.j2 " ).read_text (encoding = "utf-8" )
4949
5050mapname_re = re .compile (r'<map id="(.*?)"' )
5151_MERMAID_INIT_JS_DEFAULT = "mermaid.initialize({startOnLoad:false});"
@@ -451,6 +451,8 @@ def install_js(
451451 _has_fullscreen = app .config .mermaid_fullscreen
452452 _button_text = app .config .mermaid_fullscreen_button
453453 _button_opacity = app .config .mermaid_fullscreen_button_opacity
454+ _mermaid_width = app .config .mermaid_width
455+ _mermaid_height = app .config .mermaid_height
454456
455457 if app .config .mermaid_output_format == "raw" :
456458 if app .config .d3_use_local :
@@ -466,6 +468,10 @@ def install_js(
466468 if not _has_fullscreen :
467469 _d3_js_script = _MERMAID_RUN .format (
468470 mermaid_js_url = _mermaid_js_url ,
471+ common_css = _MERMAID_CSS .format (
472+ mermaid_width = _mermaid_width ,
473+ mermaid_height = _mermaid_height ,
474+ ),
469475 fullscreen_css = "" , # ignored
470476 button_text = _button_text , # ignored
471477 button_opacity = _button_opacity , # ignored
@@ -493,6 +499,10 @@ def install_js(
493499 if not _has_fullscreen :
494500 _d3_js_script = _MERMAID_RUN .format (
495501 mermaid_js_url = _mermaid_js_url ,
502+ common_css = _MERMAID_CSS .format (
503+ mermaid_width = _mermaid_width ,
504+ mermaid_height = _mermaid_height ,
505+ ),
496506 fullscreen_css = "" , # ignored
497507 button_text = _button_text , # ignored
498508 button_opacity = _button_opacity , # ignored
@@ -528,7 +538,14 @@ def install_js(
528538 count = - 1
529539 _d3_js_script = _MERMAID_RUN .format (
530540 mermaid_js_url = _mermaid_js_url ,
531- fullscreen_css = _FULLSCREEN_CSS ,
541+ common_css = _MERMAID_CSS .format (
542+ mermaid_width = _mermaid_width ,
543+ mermaid_height = _mermaid_height ,
544+ ),
545+ fullscreen_css = _FULLSCREEN_CSS .format (
546+ mermaid_width = _mermaid_width ,
547+ mermaid_height = _mermaid_height ,
548+ ),
532549 button_text = _button_text ,
533550 button_opacity = _button_opacity ,
534551 d3_selector = _d3_selector if _d3_selector else ".mermaid svg" ,
@@ -542,7 +559,14 @@ def install_js(
542559 # Fullscreen without zoom
543560 _fullscreen_js_script = _MERMAID_RUN .format (
544561 mermaid_js_url = _mermaid_js_url ,
545- fullscreen_css = _FULLSCREEN_CSS ,
562+ common_css = _MERMAID_CSS .format (
563+ mermaid_width = _mermaid_width ,
564+ mermaid_height = _mermaid_height ,
565+ ),
566+ fullscreen_css = _FULLSCREEN_CSS .format (
567+ mermaid_width = _mermaid_width ,
568+ mermaid_height = _mermaid_height ,
569+ ),
546570 button_text = _button_text ,
547571 button_opacity = _button_opacity ,
548572 d3_selector = "" , # ignored
@@ -558,6 +582,7 @@ def install_js(
558582 None ,
559583 body = _MERMAID_RUN .format (
560584 mermaid_js_url = _mermaid_js_url ,
585+ common_css = "" ,
561586 fullscreen_css = "" ,
562587 button_text = "" ,
563588 button_opacity = "" ,
@@ -601,6 +626,8 @@ def setup(app):
601626 app .add_config_value ("d3_use_local" , "" , "html" )
602627 app .add_config_value ("d3_version" , "7.9.0" , "html" )
603628 app .add_config_value ("mermaid_d3_zoom" , False , "html" )
629+ app .add_config_value ("mermaid_width" , "100%" , "html" )
630+ app .add_config_value ("mermaid_height" , "500px" , "html" )
604631 app .add_config_value ("mermaid_fullscreen" , True , "html" )
605632 app .add_config_value ("mermaid_fullscreen_button" , "⛶" , "html" )
606633 app .add_config_value ("mermaid_fullscreen_button_opacity" , "50" , "html" )
0 commit comments