PrismJS / prism

Lightweight, robust, elegant syntax highlighting.
https://prismjs.com
MIT License
12.28k stars 1.3k forks source link

Doesn't highlight URLs with certain hash fragments correctly #1142

Closed prtksxna closed 6 years ago

prtksxna commented 7 years ago

If the following code is higlighted:

// See documentation at: 
// https://doc.wikimedia.org/oojs-ui/master/js/#!/api/OO.ui.ButtonWidget
new OO.ui.ButtonWidget( {
    "label": "Normal"
} )

The URL in the second line is only highlighted (and turned into a link) till the # that is - https://doc.wikimedia.org/oojs-ui/master/js/# which takes the user to the wrong place.

Workaround

prism-autolinker supports Markdown syntax, so we can work around it like this:

url = 'https://doc.wikimedia.org/oojs-ui/master/js/#!/api/OO.ui.ButtonWidget';
out = '// See documentation at: \n// [' + url + '](' + url + ')\n' + out;

Details

This was discovered while creating the following patch - https://gerrit.wikimedia.org/r/#/c/356398

Golmote commented 6 years ago

Thanks for reporting! It should be fixed now.

prtksxna commented 6 years ago

Thanks @Golmote :)