|
|
@ -67,7 +67,7 @@ def filenameforlink(href):
|
|
|
|
return href
|
|
|
|
return href
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rewriteimglinks(tree):
|
|
|
|
def rewriteimglinks(tree, page):
|
|
|
|
#on Overview_main_page
|
|
|
|
#on Overview_main_page
|
|
|
|
# add link to publication on <a><img>
|
|
|
|
# add link to publication on <a><img>
|
|
|
|
|
|
|
|
|
|
|
@ -76,10 +76,13 @@ def rewriteimglinks(tree):
|
|
|
|
for a in tree.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')
|
|
|
|
href = a.attrib.get('href')
|
|
|
|
if a.findall(".//img"): # ensure a has child: img
|
|
|
|
if a.findall(".//img"): # ensure a has child: img
|
|
|
|
|
|
|
|
if page.name == 'Overview main page':
|
|
|
|
img = a.find(".//img")
|
|
|
|
img = a.find(".//img")
|
|
|
|
img_src = img.attrib['src']
|
|
|
|
img_src = img.attrib['src']
|
|
|
|
a.attrib['href'] = img_src # 'javascript:void(0);' # disable href
|
|
|
|
a.attrib['href'] = img_src
|
|
|
|
a.attrib['target'] = "_blank"
|
|
|
|
else:
|
|
|
|
|
|
|
|
a.attrib['href'] = 'javascript:void(0);' # disable href
|
|
|
|
|
|
|
|
|
|
|
|
print(a)
|
|
|
|
print(a)
|
|
|
|
print(ET.tostring(a, method="html", encoding="unicode"))
|
|
|
|
print(ET.tostring(a, method="html", encoding="unicode"))
|
|
|
|
return tree
|
|
|
|
return tree
|
|
|
@ -100,7 +103,7 @@ def rewritelinks (html):
|
|
|
|
return html
|
|
|
|
return html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rewriteimgs(html):
|
|
|
|
def rewriteimgs(html, page):
|
|
|
|
t = html5lib.parseFragment(html, treebuilder = "etree", namespaceHTMLElements = False)
|
|
|
|
t = html5lib.parseFragment(html, treebuilder = "etree", namespaceHTMLElements = False)
|
|
|
|
|
|
|
|
|
|
|
|
# replace images url with local image in ../images
|
|
|
|
# replace images url with local image in ../images
|
|
|
@ -131,7 +134,7 @@ def rewriteimgs(html):
|
|
|
|
img.attrib['width'] = ""
|
|
|
|
img.attrib['width'] = ""
|
|
|
|
img.attrib['height'] = ""
|
|
|
|
img.attrib['height'] = ""
|
|
|
|
|
|
|
|
|
|
|
|
t = rewriteimglinks(tree=t)
|
|
|
|
t = rewriteimglinks(tree=t, page=page)
|
|
|
|
|
|
|
|
|
|
|
|
html = ET.tostring(t, method="html", encoding="unicode")
|
|
|
|
html = ET.tostring(t, method="html", encoding="unicode")
|
|
|
|
return html
|
|
|
|
return html
|
|
|
@ -140,7 +143,7 @@ def dumppage(p, template, rewrite_images=True):
|
|
|
|
htmlsrc = site.parse(page=p.name)['text']['*']
|
|
|
|
htmlsrc = site.parse(page=p.name)['text']['*']
|
|
|
|
htmlsrc = rewritelinks(htmlsrc)
|
|
|
|
htmlsrc = rewritelinks(htmlsrc)
|
|
|
|
if rewrite_images:
|
|
|
|
if rewrite_images:
|
|
|
|
htmlsrc = rewriteimgs(htmlsrc)
|
|
|
|
htmlsrc = rewriteimgs(html=htmlsrc, page=p)
|
|
|
|
html = template.render(page=p, body=htmlsrc, staticpath='.')
|
|
|
|
html = template.render(page=p, body=htmlsrc, staticpath='.')
|
|
|
|
with open(os.path.join(args.output, filenameforpage(p)), 'w') as f:
|
|
|
|
with open(os.path.join(args.output, filenameforpage(p)), 'w') as f:
|
|
|
|
f.write(html)
|
|
|
|
f.write(html)
|
|
|
|