Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore markdown codeblocks for tags #66

Merged
merged 3 commits into from
May 21, 2023
Merged
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: 5 additions & 2 deletions flatnotes/flatnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from logger import logger

MARKDOWN_EXT = ".md"
INDEX_SCHEMA_VERSION = "3"
INDEX_SCHEMA_VERSION = "4"

StemmingFoldingAnalyzer = StemmingAnalyzer() | CharsetFilter(accent_map)

Expand Down Expand Up @@ -162,6 +162,7 @@ def _get_matched_fields(matched_terms):

class Flatnotes(object):
TAGS_RE = re.compile(r"(?:(?<=^#)|(?<=\s#))\w+(?=\s|$)")
CODEBLOCK_RE = re.compile(r"`{1,3}.*?`{1,3}", re.DOTALL)
TAGS_WITH_HASH_RE = re.compile(r"(?:(?<=^)|(?<=\s))#\w+(?=\s|$)")

def __init__(self, dir: str) -> None:
Expand Down Expand Up @@ -203,7 +204,9 @@ def extract_tags(cls, content) -> Tuple[str, Set[str]]:

- The content without the tags.
- A set of tags converted to lowercase."""
content_ex_tags, tags = re_extract(cls.TAGS_RE, content)
content_ex_codeblock = re.sub(cls.CODEBLOCK_RE, '', content)
_, tags = re_extract(cls.TAGS_RE, content_ex_codeblock)
content_ex_tags, _ = re_extract(cls.TAGS_RE, content)
try:
tags = [tag.lower() for tag in tags]
return (content_ex_tags, set(tags))
Expand Down