Implement semicolon for page numbers, etc. in footnotes

This commit is contained in:
RunasSudo 2020-12-20 01:14:11 +11:00
parent 205a9a8c82
commit d9e8e02831
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -427,9 +427,9 @@ class FootnoteExtension(markdown.extensions.footnotes.FootnoteExtension):
return div return div
class FootnoteInlineProcessor(markdown.extensions.footnotes.FootnoteInlineProcessor): class FootnoteInlineProcessor(markdown.extensions.footnotes.FootnoteInlineProcessor):
# Override to handle commas # Override to handle commas and semicolons
def handleMatch(self, m, data): def handleMatch(self, m, data):
id = m.group(1).rstrip(',') id = m.group(1).rstrip(',').split(';')[0]
if id in self.footnotes.footnotes.keys(): if id in self.footnotes.footnotes.keys():
sup = ET.Element("sup") sup = ET.Element("sup")
sup.set('class', 'footnote-ref') sup.set('class', 'footnote-ref')
@ -437,8 +437,13 @@ class FootnoteInlineProcessor(markdown.extensions.footnotes.FootnoteInlineProces
sup.set('id', self.footnotes.makeFootnoteRefId(id, found=True)) sup.set('id', self.footnotes.makeFootnoteRefId(id, found=True))
a.set('href', '#' + self.footnotes.makeFootnoteId(id)) a.set('href', '#' + self.footnotes.makeFootnoteId(id))
a.text = str(list(self.footnotes.footnotes.keys()).index(id) + 1) a.text = str(list(self.footnotes.footnotes.keys()).index(id) + 1)
a.tail = ''
if ';' in m.group(1):
a.tail += ' ' + m.group(1).rstrip(',').split(';')[1]
if m.group(1).endswith(','): if m.group(1).endswith(','):
a.tail = ',' a.tail = ','
return sup, m.start(0), m.end(0) return sup, m.start(0), m.end(0)
else: else:
return None, None, None return None, None, None