Reimplement Markdown linkification logic
Automatically hide links on screen and show when printing
This commit is contained in:
parent
6861a6dd97
commit
646eaf2b31
@ -20,8 +20,6 @@ import markdown.extensions.extra, markdown.extensions.footnotes, markdown.extens
|
|||||||
import re
|
import re
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from .mdx_urlize import UrlizeExtension
|
|
||||||
|
|
||||||
directives = {}
|
directives = {}
|
||||||
roles = {}
|
roles = {}
|
||||||
|
|
||||||
@ -29,7 +27,7 @@ class WNMarkdown(markdown.Markdown):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.registerExtensions([FootnoteExtension(), UrlizeExtension(), 'toc', 'tables'], {})
|
self.registerExtensions([FootnoteExtension(), 'toc', 'tables'], {})
|
||||||
|
|
||||||
self.meta = {}
|
self.meta = {}
|
||||||
|
|
||||||
@ -374,7 +372,7 @@ class FootnoteExtension(markdown.extensions.footnotes.FootnoteExtension):
|
|||||||
md.inlinePatterns.register(FootnoteInlineProcessor(FOOTNOTE_RE, self), 'footnote', 175)
|
md.inlinePatterns.register(FootnoteInlineProcessor(FOOTNOTE_RE, self), 'footnote', 175)
|
||||||
md.treeprocessors.register(markdown.extensions.footnotes.FootnoteTreeprocessor(self), 'footnote', 50)
|
md.treeprocessors.register(markdown.extensions.footnotes.FootnoteTreeprocessor(self), 'footnote', 50)
|
||||||
|
|
||||||
# Override to omit backlinks
|
# Override to omit backlinks and reformat
|
||||||
def makeFootnotesDiv(self, root):
|
def makeFootnotesDiv(self, root):
|
||||||
if not list(self.footnotes.keys()):
|
if not list(self.footnotes.keys()):
|
||||||
return None
|
return None
|
||||||
@ -387,7 +385,12 @@ class FootnoteExtension(markdown.extensions.footnotes.FootnoteExtension):
|
|||||||
for index, id in enumerate(self.footnotes.keys(), start=1):
|
for index, id in enumerate(self.footnotes.keys(), start=1):
|
||||||
li = ET.SubElement(ol, "li")
|
li = ET.SubElement(ol, "li")
|
||||||
li.set("id", self.makeFootnoteId(id))
|
li.set("id", self.makeFootnoteId(id))
|
||||||
self.parser.parseChunk(surrogate_parent, self.footnotes[id])
|
|
||||||
|
fn_src = self.footnotes[id]
|
||||||
|
fn_src = re.sub(r'(https?://[^ ]+)', r'<a href="\1" class="smart-url"><span>\[URL\]</span><span class="url">\1</span></a>', fn_src)
|
||||||
|
fn_src = re.sub(r'doi: ([^ ]+)', r'<a href="https://doi-org.ezproxy.lib.monash.edu.au/\1">doi: <span class="url">\1</span></a>', fn_src)
|
||||||
|
|
||||||
|
self.parser.parseChunk(surrogate_parent, fn_src)
|
||||||
for el in list(surrogate_parent):
|
for el in list(surrogate_parent):
|
||||||
li.append(el)
|
li.append(el)
|
||||||
surrogate_parent.remove(el)
|
surrogate_parent.remove(el)
|
||||||
|
@ -207,6 +207,22 @@ a.redlink {
|
|||||||
color: #cc0000ff !important;
|
color: #cc0000ff !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a span.url {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.smart-url > span.url {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
@media print {
|
||||||
|
a.smart-url > span.url {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
a.smart-url > span:not(.url) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
div.two-columns {
|
div.two-columns {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user