Skip to content

Commit

Permalink
Merge pull request #39 from ndy2/update-tags-regex
Browse files Browse the repository at this point in the history
update tag regex
  • Loading branch information
ndy2 authored Mar 9, 2024
2 parents daa5189 + e5856bf commit 13e724f
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion obsidian_support/conversion/tags/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TagsConversion(AbstractConversion):
@override
def obsidian_regex_pattern(self):
# OBSIDIAN_TAGS_REGEX
return re.compile(r"(?<!\\)#(?P<tags>[\w\-_\/]+)(?![^\[\(`]*[\]\)`])")
return re.compile(r"(?<!\\)#(?P<tags>[\w\-_\/]+)(?![^\[\(]*[\]\)])")

@override
def convert(self, syntax_groups: SyntaxGroup, page: Page) -> str:
Expand Down
3 changes: 2 additions & 1 deletion obsidian_support/conversion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def get_exclude_indices(markdown: str) -> List[Tuple[int, int]]:
nested_code_block_syntax = code_block_syntax
elif nested_code_block_syntax is not None and \
code_block_syntax.code_block_type == nested_code_block_syntax.code_block_type:
if not nested_code_block_syntax.language.startswith("ad-") and not nested_code_block_syntax.language == "tabs":
if not nested_code_block_syntax.language.startswith("ad-") and \
not nested_code_block_syntax.language == "tabs":
exclude_indices.append((nested_code_block_syntax.start, code_block_syntax.end))
nested_code_block_syntax = None

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

VERSION_NUMBER = '1.3.1'
VERSION_NUMBER = '1.3.2'


def read_file(fname):
Expand Down
2 changes: 1 addition & 1 deletion test/conversion/tabs/test_tabs_backquotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from obsidian_support.conversion.tabs.tabs_backquotes import TabsBackquotesConversion


def test_tag_conversion():
def test_tabs_conversion():
# given
conversion = TabsBackquotesConversion()
markdown = cleandoc("""
Expand Down
Empty file.
49 changes: 49 additions & 0 deletions test/conversion/tags/test_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from inspect import cleandoc

from assertpy import assert_that

from obsidian_support.conversion.tags.tags import TagsConversion


def test_tags_conversion_1():
# given
conversion = TagsConversion()
markdown = "#tag"

# when
converted = conversion.markdown_convert(markdown, None)

# then
assert_that(converted).is_equal_to("**tag**{: .hash}")


def test_tags_conversion_2():
# given
conversion = TagsConversion()
markdown = cleandoc("""
#tag
```tabs
---tab obsidian markdown
~~~
This is just an #obsidian tag. Click to go to the search bar
~~~
---tab mkdocs-material rendered
This is just an #obsidian tag. Click to go to the search bar
```
""")

# when
converted = conversion.markdown_convert(markdown, None)

# then
assert_that(converted).is_equal_to(cleandoc("""
**tag**{: .hash}
```tabs
---tab obsidian markdown
~~~
This is just an #obsidian tag. Click to go to the search bar
~~~
---tab mkdocs-material rendered
This is just an **obsidian**{: .hash} tag. Click to go to the search bar
```
"""))
20 changes: 20 additions & 0 deletions test/conversion/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,23 @@ def test_get_exclude_indices_5():

# then
print(exclude_indices)


def test_get_exclude_indices_6():
# given
markdown = cleandoc("""
```tabs
---tab obsidian markdown
~~~
This is just an #obsidian tag. Click to go to the search bar
~~~
---tab mkdocs-material rendered
This is just an #obsidian tag. Click to go to the search bar
```
""")

# when
exclude_indices = get_exclude_indices(markdown)

# then
print(exclude_indices)

0 comments on commit 13e724f

Please sign in to comment.