From 0fdbd3d221922367c8495d29d30f9a215e60bd89 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Tue, 27 Feb 2024 23:15:03 -0700 Subject: [PATCH] started properly parsing the Obsidian link references --- src/dragonglass/mparse.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dragonglass/mparse.py b/src/dragonglass/mparse.py index de4d6d3..b9974fa 100644 --- a/src/dragonglass/mparse.py +++ b/src/dragonglass/mparse.py @@ -28,11 +28,21 @@ class ObsidianLinks(Extension): def __init__(self, pattern, md): super(ObsidianLinks.ObsidianLinksProc, self).__init__(pattern, md) + def parse_reference(self, contents): + text = None + t = contents.split('|') + if len(t) > 1: + text = t[1] + contents = t[0] + if not text: + text = contents + return contents, text + def handleMatch(self, m, data): - dstr = m.group(0)[2:-2] + link, text = self.parse_reference(m.group(0)[2:-2]) el = etree.Element('a') - el.set('href', dstr) - el.text = dstr + el.set('href', link) + el.text = text return el, m.start(0), m.end(0) def extendMarkdown(self, md):