Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
westurner opened this issue Mar 3, 2019 · 3 comments
Open

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

westurner opened this issue Mar 3, 2019 · 3 comments

Comments

@westurner
Copy link
Member

westurner commented Mar 3, 2019

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
Copy link
Member Author

westurner commented Mar 3, 2019

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
Copy link
Member Author

westurner commented Mar 3, 2019

This could be very helpful on mobile devices.

Sorry, something went wrong.

@westurner
Copy link
Member Author

Additional patterns:

  • twitter.com/([\w-_]+) -> @username 🐦
  • itunes.apple.com/us/app/([\w-]+)/id\d+ -> appname :ios:
  • play.google.com/store/apps/details?id=([\w.-_]+) -> appname :android:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant