mediawiki-extensions-Discus.../modules/dt.debug.js
Bartosz Dziewoński 37c9f49cff Re-add debug highlighter
We removed it in c40c112514 when we added
a more practical use for the parser, but I keep wishing I had it to
experiment with the parser code.

Now it's off by default and can be used by adding &dtdebug=1 to the URL.

Change-Id: I6a92bfe7f55af0949b391606b04c3cfa0f996f2a
2019-10-24 23:21:40 +02:00

25 lines
1 KiB
JavaScript

var
parser = require( 'ext.discussionTools.parser' ),
highlighter = require( './highlighter.js' ),
timestamps, comments, threads, i, node, match, signature, emptySignature;
timestamps = parser.findTimestamps( document.getElementById( 'mw-content-text' ) );
comments = parser.getComments( document.getElementById( 'mw-content-text' ) );
threads = parser.groupThreads( comments );
highlighter.markThreads( threads );
for ( i = 0; i < timestamps.length; i++ ) {
node = timestamps[ i ][ 0 ];
match = timestamps[ i ][ 1 ];
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 );
}
}