mediawiki-extensions-Discus.../modules/dt.debug.js
Ed Sanders 092cfd6075 Parser: Replace findTimestamps with findTimestamp
Instead of doing a separate tree walk and finding all timestamps
separately, make it part of the getComments tree walk, and find
timestamps one at a time.

Change-Id: I47f466eaf228504faa189fd99e07493bc7f022cd
2020-07-15 21:34:22 +02:00

30 lines
1.1 KiB
JavaScript

var
parser = require( 'ext.discussionTools.init' ).parser,
highlighter = require( './highlighter.js' ),
comments = parser.getComments( document.getElementById( 'mw-content-text' ) ),
threads = parser.groupThreads( comments ),
timestampRegex = parser.getLocalTimestampRegexp();
highlighter.markThreads( threads );
// TODO: Use comment.signatureRanges to mark up signatures/timestamps
comments.forEach( function ( comment ) {
var signature, emptySignature, node, match;
if ( comment.type !== 'comment' ) {
return;
}
node = comment.range.endContainer;
match = parser.findTimestamp( node, timestampRegex );
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
// don't care about it. The code below doesn't mark that due to now the text nodes are sliced,
// but we might need to take care to use the matched range of node in other cases.
highlighter.markTimestamp( node, match );
if ( !emptySignature ) {
highlighter.markSignature( signature );
}
} );