started properly parsing the Obsidian link references

This commit is contained in:
Amy G. Bowersox 2024-02-27 23:15:03 -07:00
parent d8cd92764f
commit 0fdbd3d221

View File

@ -28,11 +28,21 @@ class ObsidianLinks(Extension):
def __init__(self, pattern, md): def __init__(self, pattern, md):
super(ObsidianLinks.ObsidianLinksProc, self).__init__(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): 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 = etree.Element('a')
el.set('href', dstr) el.set('href', link)
el.text = dstr el.text = text
return el, m.start(0), m.end(0) return el, m.start(0), m.end(0)
def extendMarkdown(self, md): def extendMarkdown(self, md):