wrdrd / docs

WRD R&D Documentation – https://wrdrd.github.io/docs/
https://wrdrd.github.io/docs/
9 stars 1 forks source link

ENH,UBY: strip https, en.wikipedia.org w/ JS #21

Open westurner opened 5 years ago

westurner commented 5 years ago
links = $('a.reference.external');
function striphttps(a, link) { 
    if (link.text.startsWith('https://')) {
        link.text = link.text.substring(8); }
}
links.map(striphttps);
function stripenwikipedia(a, link) { 
    if (link.text.startsWith('en.wikipedia.org/wiki/')) {
        if (link.previousSibling !== null && link.previousSibling.textContent.startsWith('Wikipedia:')) {
            link.text = link.text.substring(22);
        } else {
            link.text = "wikipedia: " + link.text.substring(22);
        }
    }
}
links.map(stripenwikipedia);

[EDIT]

The code for this lives in westurner/sphinx_wrd_theme: https://github.com/westurner/wrd_sphinx_theme/blob/master/wrd_sphinx_theme/template/static/js/linkstyles.js

westurner commented 5 years ago

This should be optional so that copy/paste to non-HTML formats doesn't break links (and strip the helpful https:// part)

One approach would be to store the original link text as an extra attribute and revert when the toggle checkbox is clicked.

westurner commented 5 years ago

This could be very helpful on mobile devices.

westurner commented 5 years ago

Additional patterns: