improved end of list detection and image dimension detection
This commit is contained in:
parent
3a27bf5664
commit
7a5011fa88
|
@ -112,7 +112,7 @@ class MetaStripper(Extension):
|
||||||
|
|
||||||
class ObsidianImages(Extension):
|
class ObsidianImages(Extension):
|
||||||
"""An extension that supports image tags the way Obsidian handles them."""
|
"""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:
|
def __init__(self, context: Context, **kwargs: dict[str, Any]) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -451,6 +451,16 @@ class ObsidianLists(Extension):
|
||||||
TASK_RE = re.compile(r'^([ ]*)-[ ]\[(.)\][ ]+(.*)')
|
TASK_RE = re.compile(r'^([ ]*)-[ ]\[(.)\][ ]+(.*)')
|
||||||
LIST_START = STX + "erbosoft:lstart" + ETX
|
LIST_START = STX + "erbosoft:lstart" + ETX
|
||||||
LIST_END = STX + "erbosoft:lend" + 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]:
|
def _find_listhead(self, line) -> tuple[str, int, int]:
|
||||||
"""
|
"""
|
||||||
|
@ -466,7 +476,7 @@ class ObsidianLists(Extension):
|
||||||
"""
|
"""
|
||||||
m = self.UL_RE.match(line)
|
m = self.UL_RE.match(line)
|
||||||
if m:
|
if m:
|
||||||
if line.lstrip() == '* * *':
|
if self.is_horizontal_rule(line):
|
||||||
# this is actually a horizontal rule, don't trip on it
|
# this is actually a horizontal rule, don't trip on it
|
||||||
return '', -1, -1
|
return '', -1, -1
|
||||||
return 'ul', len(m.group(1)), -1
|
return 'ul', len(m.group(1)), -1
|
||||||
|
@ -501,7 +511,8 @@ class ObsidianLists(Extension):
|
||||||
in_list = False
|
in_list = False
|
||||||
while i < len(lines):
|
while i < len(lines):
|
||||||
if in_list:
|
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
|
in_list = False
|
||||||
lines.insert(i, self._extref.LIST_END)
|
lines.insert(i, self._extref.LIST_END)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user