Skip to content

Commit

Permalink
fix: Only preserve tags in titles if Material for MkDocs' `content.to…
Browse files Browse the repository at this point in the history
…oltips` feature is enabled
  • Loading branch information
pawamoy committed Feb 24, 2025
1 parent b653e01 commit b21aefd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ plugins:

[instant-preview]: https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/#instant-previews

By default, HTML tags are only preserved in titles if the current theme in use in Material for MkDocs. If the theme you are using does support HTML tags titles, you can prevent tags stripping with the `strip_title_tags` option:
By default, HTML tags are only preserved in titles if the current theme in use is Material for MkDocs and its `content.tooltips` feature is enabled. If your chosen theme does support HTML tags in titles, you can prevent tags stripping with the `strip_title_tags` option:

```yaml
plugins:
Expand Down
5 changes: 4 additions & 1 deletion src/mkdocs_autorefs/_internal/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
self._link_titles = self.config.link_titles

if self.config.strip_title_tags == "auto":
if getattr(config.theme, "name", None) == "material":
if getattr(config.theme, "name", None) == "material" and "content.tooltips" in config.theme.get(
"features",
(),
):
self._strip_title_tags = False
else:
self._strip_title_tags = True
Expand Down
6 changes: 5 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_auto_strip_title_tags_false() -> None:
plugin.config = AutorefsConfig()
plugin.config.strip_title_tags = "auto"
config = MkDocsConfig()
config.theme = Theme(name="material")
config.theme = Theme(name="material", features=["content.tooltips"])
plugin.on_config(config=config)
assert plugin._strip_title_tags is False

Expand All @@ -195,6 +195,10 @@ def test_auto_strip_title_tags_true() -> None:
plugin.config.strip_title_tags = "auto"
config = MkDocsConfig()

config.theme = Theme(name="material", features=[])
plugin.on_config(config=config)
assert plugin._strip_title_tags is True

config.theme = Theme("mkdocs")
plugin.on_config(config=config)
assert plugin._strip_title_tags is True
Expand Down

0 comments on commit b21aefd

Please sign in to comment.