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
2 changes: 1 addition & 1 deletion src/rockgarden/obsidian/inline_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from rockgarden.urls import get_tag_url, normalize_tag

INLINE_TAG_PATTERN = re.compile(r"(?<!\w)#([a-zA-Z][\w-]*(?:/[\w-]+)*)")
INLINE_TAG_PATTERN = re.compile(r"(?<![\w&])#([a-zA-Z][\w-]*(?:/[\w-]+)*)")
# Protect code blocks AND markdown links from tag extraction
PROTECTED_PATTERN = re.compile(
r"```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]+`|\[[^\]]*\]\([^)]*\)"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_inline_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ def test_not_in_anchor_link(self):
assert tags == []
assert content == "[Jump](#introduction)"

def test_not_in_html_entity(self):
content, tags = extract_inline_tags("Freemen&#x27;s Wood")
assert tags == []
assert content == "Freemen&#x27;s Wood"

def test_not_in_numeric_html_entity(self):
content, tags = extract_inline_tags("&#xABCD;")
assert tags == []

def test_tag_after_html_entity_still_works(self):
content, tags = extract_inline_tags("Tom&#x27;s #python notes")
assert tags == ["python"]

def test_not_in_markdown_link_text(self):
content, tags = extract_inline_tags("[text with #python](http://example.com)")
assert tags == []
Expand Down
Loading