From f0baf9a1d2293a34438c7c473e0f5361df874122 Mon Sep 17 00:00:00 2001 From: Erin Shaben Date: Wed, 1 Apr 2026 00:28:38 -0400 Subject: [PATCH] strip pymdownx attribute blocks from inline links in output --- plugins/ai_docs/plugin.py | 7 +++++++ tests/ai_docs/test_ai_docs.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/plugins/ai_docs/plugin.py b/plugins/ai_docs/plugin.py index 1100f6f..ef683ad 100644 --- a/plugins/ai_docs/plugin.py +++ b/plugins/ai_docs/plugin.py @@ -610,6 +610,8 @@ def on_post_build(self, config): cleaned_body = self.remove_html_comments(resolved_body) if cleaned_body != resolved_body: log.debug(f"[ai_docs] stripped HTML comments in {md_path}") + # Remove pymdownx attribute blocks from inline links + cleaned_body = self.remove_attribute_syntax(cleaned_body) # Convert path to slug and canonical URLs rel_path = Path(md_path).relative_to(docs_dir) rel_no_ext = str(rel_path.with_suffix("")) @@ -1235,6 +1237,11 @@ def remove_html_comments(content: str) -> str: """Remove comments (multiline).""" return re.sub(r"", "", content, flags=re.DOTALL) + @staticmethod + def remove_attribute_syntax(content: str) -> str: + """Remove pymdownx attribute blocks from inline links e.g. [text](url){target=\_blank}.""" + return re.sub(r"(?<=\))\s*\{[^}]+\}", "", content) + @staticmethod def strip_snippet_section_markers(content: str) -> str: """Remove snippet section markers (# --8<-- [start:end]) from snippet content.""" diff --git a/tests/ai_docs/test_ai_docs.py b/tests/ai_docs/test_ai_docs.py index e01b0d7..16e380c 100644 --- a/tests/ai_docs/test_ai_docs.py +++ b/tests/ai_docs/test_ai_docs.py @@ -418,6 +418,20 @@ def test_metadata_section_includes_versioning(self): assert "Version Hash: sha256:" in section +# =========================================================================== +# Cleanup methods +# =========================================================================== + +class TestRemoveAttributeSyntax: + def test_strips_attribute_block_from_inline_link(self): + content = "[Link](https://example.com){target=\\_blank}" + assert AIDocsPlugin.remove_attribute_syntax(content) == "[Link](https://example.com)" + + def test_no_attribute_block_unchanged(self): + content = "[Link](https://example.com)" + assert AIDocsPlugin.remove_attribute_syntax(content) == content + + # =========================================================================== # Page exclusions (ported from test_ai_page_actions) # ===========================================================================