Skip to content

Commit a0686ef

Browse files
authored
Merge pull request p12tic#69 from PeterFeicht/link-fixes
Link fixes
2 parents 9af1183 + 59210a7 commit a0686ef

File tree

9 files changed

+1482
-58
lines changed

9 files changed

+1482
-58
lines changed

commands/preprocess.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,27 +301,39 @@ def remove_ads(html):
301301
if el.text is not None and '#carbonads' in el.text:
302302
el.getparent().remove(el)
303303

304+
# remove links to file info pages (e.g. on images)
305+
def remove_fileinfo(html):
306+
info = etree.XPath(r"//a[re:test(@href, 'https?://[a-z]+\.cppreference\.com/w/File:')]/..",
307+
namespaces={'re':'http://exslt.org/regular-expressions'})
308+
for el in info(html):
309+
el.getparent().remove(el)
310+
311+
# remove external links to unused resources
312+
def remove_unused_external(html):
313+
for el in html.xpath('/html/head/link'):
314+
if el.get('rel') in ('alternate', 'search', 'edit', 'EditURI'):
315+
el.getparent().remove(el)
316+
elif el.get('rel') == 'shortcut icon':
317+
(head, tail) = os.path.split(el.get('href'))
318+
el.set('href', os.path.join(head, 'common', tail))
319+
304320
def preprocess_html_file(root, fn, rename_map):
305321
parser = etree.HTMLParser()
306322
html = etree.parse(fn, parser)
307323
output = io.StringIO()
308324

309-
# remove external links to unused resources
310-
for el in html.xpath('/html/head/link'):
311-
if el.get('rel') in [ 'alternate', 'search', 'edit', 'EditURI' ]:
312-
el.getparent().remove(el)
313-
325+
remove_unused_external(html)
314326
remove_noprint(html)
315327
remove_see_also(html)
316328
remove_google_analytics(html)
317329
remove_ads(html)
330+
remove_fileinfo(html)
318331

319332
# apply changes to links caused by file renames
320-
for el in html.xpath('//*[@src or @href]'):
321-
if el.get('src') is not None:
322-
el.set('src', transform_link(rename_map, el.get('src'), fn, root))
323-
elif el.get('href') is not None:
324-
el.set('href', transform_link(rename_map, el.get('href'), fn, root))
333+
for el in html.xpath('//*[@src]'):
334+
el.set('src', transform_link(rename_map, el.get('src'), fn, root))
335+
for el in html.xpath('//*[@href]'):
336+
el.set('href', transform_link(rename_map, el.get('href'), fn, root))
325337

326338
for err in parser.error_log:
327339
print("HTML WARN: {0}".format(err), file=output)
@@ -339,6 +351,8 @@ def preprocess_css_file(fn):
339351
text = text.replace('../DejaVuSansMonoCondensed60.ttf', 'DejaVuSansMonoCondensed60.ttf')
340352
text = text.replace('../DejaVuSansMonoCondensed75.ttf', 'DejaVuSansMonoCondensed75.ttf')
341353

354+
text = text.replace('../../upload.cppreference.com/mwiki/images/', 'images/')
355+
342356
# QT Help viewer doesn't understand nth-child
343357
text = text.replace('nth-child(1)', 'first-child')
344358

tests/preprocess_data/fabs.html

Lines changed: 53 additions & 46 deletions
Large diffs are not rendered by default.

tests/preprocess_data/fabs_ads.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ <h3><span class="editsection">[<a href="https://en.cppreference.com/mwiki/index.
462462
<h3><span class="editsection">[<a href="https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/math/fabs&amp;action=edit&amp;section=2" title="Edit section: Return value">edit</a>]</span> <span class="mw-headline" id="Return_value">Return value</span></h3>
463463
<p>If successful, returns the absolute value of <code>arg</code> (<code>|arg|</code>). The value returned is exact and does not depend on any rounding modes.
464464
</p>
465+
<div class="t-inheritance-diagram">
466+
<div class="center"><div class="noresize" style="height: 377px; width: 549px; "><map name="ImageMap_1_1158767600"><area href="io/ios_base.html" shape="rect" coords="225,4,328,36" alt="cpp/io/ios base" title="cpp/io/ios base"><area href="io/basic_ios.html" shape="rect" coords="218,62,335,100" alt="cpp/io/basic ios" title="cpp/io/basic ios"><area href="io/basic_istream.html" shape="rect" coords="305,126,422,164" alt="cpp/io/basic istream" title="cpp/io/basic istream"><area href="io/basic_ifstream.html" shape="rect" coords="419,319,536,357" alt="cpp/io/basic ifstream" title="cpp/io/basic ifstream"><area href="io/basic_istringstream.html" shape="rect" coords="410,255,545,292" alt="cpp/io/basic istringstream" title="cpp/io/basic istringstream"><area href="io/basic_ostream.html" shape="rect" coords="130,126,247,164" alt="cpp/io/basic ostream" title="cpp/io/basic ostream"><area href="io/basic_ofstream.html" shape="rect" coords="14,319,132,357" alt="cpp/io/basic ofstream" title="cpp/io/basic ofstream"><area href="io/basic_ostringstream.html" shape="rect" coords="4,255,143,292" alt="cpp/io/basic ostringstream" title="cpp/io/basic ostringstream"><area href="io/basic_fstream.html" shape="rect" coords="200,319,318,357" alt="cpp/io/basic fstream" title="cpp/io/basic fstream"><area href="io/basic_stringstream.html" shape="rect" coords="193,255,325,292" alt="cpp/io/basic stringstream" title="cpp/io/basic stringstream"><area href="io/basic_iostream.html" shape="rect" coords="221,190,339,228" alt="cpp/io/basic iostream" title="cpp/io/basic iostream"></map><img alt="std-io-complete-inheritance.svg" src="../../../upload.cppreference.com/mwiki/images/0/06/std-io-complete-inheritance.svg" width="549" height="377" usemap="#ImageMap_1_1158767600"><div style="margin-left: 529px; margin-top: -20px; text-align: left;"><a href="https://en.cppreference.com/w/File:std-io-complete-inheritance.svg" title="About this image"><img alt="About this image" src="../../mwiki/extensions/ImageMap/desc-20.png" style="border: none;"></a></div></div></div>
467+
<div style="text-align:center;">
468+
<p><span style="font-size:0.7em; line-height:130%">Inheritance diagram</span>
469+
</p>
470+
</div>
471+
</div>
465472
<h3><span class="editsection">[<a href="https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/math/fabs&amp;action=edit&amp;section=3" title="Edit section: Error handling">edit</a>]</span> <span class="mw-headline" id="Error_handling">Error handling</span></h3>
466473
<p>This function is not subject to any of the error conditions specified in <a href="math_errhandling.html" title="cpp/numeric/math/math errhandling">math_errhandling</a>
467474
</p><p>If the implementation supports IEEE floating-point arithmetic (IEC 60559),

0 commit comments

Comments
 (0)