From 7a5011fa8827bbaa01d74697ebbee8197de943ab Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Wed, 14 Aug 2024 22:21:44 -0600 Subject: [PATCH] improved end of list detection and image dimension detection --- src/dragonglass/mparse.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dragonglass/mparse.py b/src/dragonglass/mparse.py index 76f80b4..997358a 100644 --- a/src/dragonglass/mparse.py +++ b/src/dragonglass/mparse.py @@ -112,7 +112,7 @@ class MetaStripper(Extension): class ObsidianImages(Extension): """An extension that supports image tags the way Obsidian handles them.""" - __DIMS = re.compile(r'(.*)\|(\d+)(?:x(\d+))?') + __DIMS = re.compile(r'(.*)\|[ ]*(\d+)(?:[ ]*x[ ]*(\d+))?') def __init__(self, context: Context, **kwargs: dict[str, Any]) -> None: """ @@ -451,6 +451,16 @@ class ObsidianLists(Extension): TASK_RE = re.compile(r'^([ ]*)-[ ]\[(.)\][ ]+(.*)') LIST_START = STX + "erbosoft:lstart" + ETX LIST_END = STX + "erbosoft:lend" + ETX + HORZ_RULES = ['***', '* * *', '---', '- - -', '___', '_ _ _'] + + def is_horizontal_rule(self, line): + """ + Returns ``True`` if this line is a horizontal rule, ``False`` if not. + + Args: + line The line to be tested: + """ + return line.lstrip() in self.HORZ_RULES def _find_listhead(self, line) -> tuple[str, int, int]: """ @@ -466,7 +476,7 @@ class ObsidianLists(Extension): """ m = self.UL_RE.match(line) if m: - if line.lstrip() == '* * *': + if self.is_horizontal_rule(line): # this is actually a horizontal rule, don't trip on it return '', -1, -1 return 'ul', len(m.group(1)), -1 @@ -501,7 +511,8 @@ class ObsidianLists(Extension): in_list = False while i < len(lines): if in_list: - if len(lines[i].strip()) == 0: + if (len(lines[i].strip()) == 0 or lines[i].startswith('#') + or self._extref.is_horizontal_rule(lines[i])): in_list = False lines.insert(i, self._extref.LIST_END) i += 1