image parent links: link to image file

pull/9/head
Castro0o 4 years ago
parent cf532723f8
commit 4426fbca8b

@ -55,15 +55,25 @@ def filenameforlink(href):
href = urlquote(href)
return href
def rewritelinks (html):
t = html5lib.parseFragment(html, treebuilder = "etree", namespaceHTMLElements = False)
def rewriteimglinks(tree):
# t = html5lib.parseFragment(html, treebuilder = "etree", namespaceHTMLElements = False)
# invoke after img src have be rewritten
# remove links to wiki File: pages
for a in t.findall(".//a[@class='image']"): # select img wrapping a
for a in tree.findall(".//a[@class='image']"): # select img wrapping a
href = a.attrib.get('href')
if a.findall(".//img") and 'File:' in href: # ensure a has child: img
a.attrib['href'] = 'javascript:void(0);' # disable href
if a.findall(".//img"): # ensure a has child: img
img = a.find(".//img")
img_src = img.attrib['src']
a.attrib['href'] = img_src # 'javascript:void(0);' # disable href
a.attrib['target'] = "_blank"
print(a)
print(ET.tostring(a, method="html", encoding="unicode"))
return tree
def rewritelinks (html):
t = html5lib.parseFragment(html, treebuilder = "etree", namespaceHTMLElements = False)
for a in t.findall(".//*[@href]"):
linkclass = a.attrib.get("class", "")
href = a.attrib.get("href")
@ -108,6 +118,9 @@ def rewriteimgs(html):
img.attrib['srcset'] = "" # rm srcset value:it prevent imgs displaying
img.attrib['width'] = ""
img.attrib['height'] = ""
t = rewriteimglinks(tree=t)
html = ET.tostring(t, method="html", encoding="unicode")
return html

@ -12,5 +12,3 @@ a:hover {
text-decoration: none;
color: blue;
}
a.image {cursor: default!important;} /* KEEP THIS: it is important to avoid images to seeming like links */
Loading…
Cancel
Save