Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugins/ai_docs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(""))
Expand Down Expand Up @@ -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."""
Expand Down
14 changes: 14 additions & 0 deletions tests/ai_docs/test_ai_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# ===========================================================================
Expand Down