Skip to content
Open
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
17 changes: 17 additions & 0 deletions obsidiantools/md_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ def get_tags(filepath: Path, *, show_nested: bool = False) -> list[str]:
# remove wikilinks so that '#' headers are not caught:
src_txt = _remove_wikilinks_from_source_text(src_txt)
tags = _get_tags_from_source_text(src_txt, show_nested=show_nested)
# get tags from front matter
front_matter = get_front_matter(filepath)
tags.extend(_get_tags_from_front_matter(front_matter))
# remove duplicate tags
tags = list(set(tags))
return tags


def _get_tags_from_front_matter(front_matter: dict) -> list[str]:
"""front_matter -> tags"""
# Check for front matter tags.
if 'tags' not in front_matter: return []
tags = front_matter['tags']
# Sometimes there are None values. Make sure it is a list.
if type(tags) is not list: return []
# Strip any redundant '#' characters.
tags = [ x.strip('#') for x in tags ]
return tags


Expand Down