Skip to content

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

Open

Description

@westurner
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

Activity

  1. westurner commented on Mar 3, 2019

    @westurner
    MemberAuthor

    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.

  2. westurner commented on Mar 3, 2019

    @westurner
    MemberAuthor

    This could be very helpful on mobile devices.

  3. westurner commented on Mar 3, 2019

    @westurner
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions