From 4426fbca8b382c62d007e11c10fe937658bbe732 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Thu, 16 Apr 2020 11:36:57 +0200 Subject: [PATCH] image parent links: link to image file --- dumpwiki.py | 23 ++++++++++++++++++----- static/archive.css | 2 -- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dumpwiki.py b/dumpwiki.py index 7a37930..c4fc24e 100644 --- a/dumpwiki.py +++ b/dumpwiki.py @@ -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 diff --git a/static/archive.css b/static/archive.css index fd416eb..b3dea09 100644 --- a/static/archive.css +++ b/static/archive.css @@ -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 */ \ No newline at end of file