ode-link: Fix link for URLs without protocol

Prepend '//' to relative URLs to turn them to real new (root)
addresses instead of relative paths in current domain

Bug: T368166
Follow-up: I999937c1f6303ecc64adb6285e73a9ce10f67bd8
Change-Id: I2cf901c7b0454517dc93ea8113dcf69832584c08
This commit is contained in:
Ammarpad 2024-09-26 09:04:25 +01:00
parent 0159930cdd
commit ba35957b9b

View file

@ -25,9 +25,14 @@ $( () => {
link.classList.add( 'code-link' );
if ( URLMatch ) {
const URL = URLMatch[ 0 ];
link.href = URL;
linkText = URL;
let url = URLMatch[ 0 ];
if ( !/^https?:/i.test( url ) ) {
url = '//' + url;
}
link.href = url;
linkText = URLMatch[ 0 ]; // Preserve visual link text as is
} else if ( wikilinkMatch ) {
linkText = wikilinkMatch[ 0 ];
title = mw.Title.newFromText( wikilinkMatch[ 1 ] );