From ca41a405ec3cb1ba3488185de819ebff2e81e68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 24 Sep 2020 19:32:13 +0200 Subject: [PATCH] Fix debug mode after language variant changes Follow-up to 329df8c953446c419a2d3eca48934c475bcd0353. Change-Id: I49f7d580a7e7c5dde7c234ca8905157e6a0f4f5d --- modules/dt.debug.js | 7 +++++-- modules/highlighter.js | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/dt.debug.js b/modules/dt.debug.js index 3efaa5bf3..a6c74386c 100644 --- a/modules/dt.debug.js +++ b/modules/dt.debug.js @@ -4,7 +4,7 @@ var parser = new Parser( document.getElementById( 'mw-content-text' ) ), comments = parser.getCommentItems(), threads = parser.getThreads(), - timestampRegex = parser.getLocalTimestampRegexp(); + timestampRegexps = parser.getLocalTimestampRegexps(); highlighter.markThreads( threads ); @@ -13,7 +13,10 @@ comments.forEach( function ( comment ) { var signature, emptySignature, node, match; node = comment.range.endContainer; - match = parser.findTimestamp( node, timestampRegex ); + match = parser.findTimestamp( node, timestampRegexps ); + if ( !match ) { + return; + } signature = parser.findSignature( node )[ 0 ]; emptySignature = signature.length === 1 && signature[ 0 ] === node; // Note that additional content may follow the timestamp (e.g. in some voting formats), but we diff --git a/modules/highlighter.js b/modules/highlighter.js index fc1c500b4..d8797a01b 100644 --- a/modules/highlighter.js +++ b/modules/highlighter.js @@ -4,18 +4,18 @@ var initialOffset, indentWidth; function markTimestamp( parser, node, match ) { var - dfParser = parser.getLocalTimestampParser(), + dfParsers = parser.getLocalTimestampParsers(), newNode, wrapper, date; - newNode = node.splitText( match.index ); - newNode.splitText( match[ 0 ].length ); + newNode = node.splitText( match.matchData.index ); + newNode.splitText( match.matchData[ 0 ].length ); wrapper = document.createElement( 'span' ); wrapper.className = 'detected-timestamp'; // We might need to actually port all the date formatting code from MediaWiki's PHP code // if we want to support displaying dates in all the formats available in user preferences // (which include formats in several non-Gregorian calendars). - date = dfParser( match ); + date = dfParsers[ match.parserIndex ]( match.matchData ); wrapper.title = date.format() + ' / ' + date.fromNow(); wrapper.appendChild( newNode ); node.parentNode.insertBefore( wrapper, node.nextSibling );