Skip to content

Commit

Permalink
feat: Allow markup around inline field names.
Browse files Browse the repository at this point in the history
This puts the parser on par with the reference one which is [Dataview's inline-field.ts](https://github.com/blacksmithgu/obsidian-dataview/blob/81ba6a0dd31d6562de852144112922bb33e084d9/src/data-import/inline-field.ts#L159).

Support for emojis is left behind.

Fixes selimrbd#16.
  • Loading branch information
ngirard committed Mar 23, 2023
1 parent 17f1ede commit 128e852
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pyomd/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,15 @@ class InlineMetadata(Metadata):
metadata dictionary
"""

KEY_PART_REGEX = r"([0-9\p{Letter}\w\s_/-]+)"
MARKUP_CHARS_REGEX = r'[_*~`]*'
FULL_LINE_KEY_REGEX = r"[^0-9\w\p{Letter}]*" + KEY_PART_REGEX + MARKUP_CHARS_REGEX

TMP_REGEX = Template(r"(?P<beg>.*?)(?P<key>$key)::(?P<values>.*)")
TMP_REGEX_ENCLOSED = Template(
r"(?P<beg>.*?)(?P<open>[(\[])(?P<key>$key)::(?P<values>.*?)(?P<close>[)\]])(?P<end>.*)"
)
REGEX = re.compile(TMP_REGEX.substitute(key="[A-z][A-z0-9_ -]*"))
REGEX = re.compile(TMP_REGEX.substitute(key=FULL_LINE_KEY_REGEX))
REGEX_ENCLOSED = re.compile(TMP_REGEX_ENCLOSED.substitute(key=".*?"))

def to_string(
Expand Down Expand Up @@ -513,7 +517,7 @@ def _parse_1(cls, note_content: str) -> MetaDict:

tmp: dict[str, list[str]] = dict()
for m in matches:
k = m.group("key").strip()
k = re.sub(cls.MARKUP_CHARS_REGEX, '', m.group("key")).strip() # Remove markup characters and strip whitespace
v = m.group("values")
tmp[k] = tmp.get(k, "") + ", " + v
metadata: MetaDict = {
Expand Down

0 comments on commit 128e852

Please sign in to comment.