diff --git a/mkdocs_likec4/parser.py b/mkdocs_likec4/parser.py index bb06adb..bb4abb0 100644 --- a/mkdocs_likec4/parser.py +++ b/mkdocs_likec4/parser.py @@ -70,7 +70,9 @@ def to_html(cls, opts: ViewOptions) -> str: ) tag = f"{opts.project.lower()}-view" if valid_project else "likec4-view" - return ( - f'<{tag} view-id="{escape(opts.view_id, quote=True)}" ' - f'browser="{opts.browser}" dynamic-variant="{opts.dynamic_variant}">' - ) + attrs = f'view-id="{escape(opts.view_id, quote=True)}"' + if opts.browser != "true": + attrs += f' browser="{opts.browser}"' + if opts.dynamic_variant != "diagram": + attrs += f' dynamic-variant="{opts.dynamic_variant}"' + return f"<{tag} {attrs}>" diff --git a/tests/test_parser.py b/tests/test_parser.py index 516768b..863fd95 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -251,28 +251,19 @@ def test_basic_html_output(self): """Test basic HTML output without project.""" opts = ViewOptions(view_id="my-view") html = LikeC4Parser.to_html(opts) - assert ( - html - == '' - ) + assert html == '' def test_html_with_project(self): """Test HTML output with valid project.""" opts = ViewOptions(view_id="my-view", project="myproject") html = LikeC4Parser.to_html(opts) - assert ( - html - == '' - ) + assert html == '' def test_html_with_uppercase_project(self): """Test HTML output with uppercase project (should be lowercased).""" opts = ViewOptions(view_id="my-view", project="MyProject") html = LikeC4Parser.to_html(opts) - assert ( - html - == '' - ) + assert html == '' def test_html_with_custom_options(self): """Test HTML output with custom options.""" @@ -288,14 +279,25 @@ def test_html_with_custom_options(self): == '' ) + def test_html_omits_only_default_browser(self): + """Only dynamic-variant is emitted when browser is at default.""" + opts = ViewOptions(view_id="v", dynamic_variant="sequence") + html = LikeC4Parser.to_html(opts) + assert ( + html == '' + ) + + def test_html_omits_only_default_dynamic_variant(self): + """Only browser is emitted when dynamic-variant is at default.""" + opts = ViewOptions(view_id="v", browser="false") + html = LikeC4Parser.to_html(opts) + assert html == '' + def test_html_with_invalid_project_falls_back(self): """Test HTML output with invalid project name falls back to likec4-view.""" opts = ViewOptions(view_id="my-view", project="123invalid") html = LikeC4Parser.to_html(opts) - assert ( - html - == '' - ) + assert html == '' def test_html_escapes_invalid_view_id_with_quotes(self): """Test that invalid view ID with quotes is escaped to prevent XSS."""