mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
a122e51eec
serialized into a single data-mw-rt attribute if present. Update parserTests to ignore this attribute for comparisons with expected parser output. A few more tweaks and notes are thrown into this commit too. 233 tests are passing now.
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
/**
|
|
* Simple noinclude / onlyinclude implementation. Strips all tokens in
|
|
* noinclude sections.
|
|
*
|
|
* @author Gabriel Wicke <gwicke@wikimedia.org>
|
|
*/
|
|
|
|
var TokenCollector = require( './ext.util.TokenCollector.js' ).TokenCollector;
|
|
|
|
|
|
function NoInclude( manager, isInclude ) {
|
|
new TokenCollector(
|
|
manager,
|
|
function ( tokens ) {
|
|
if ( isInclude ) {
|
|
manager.env.tp( 'noinclude stripping' );
|
|
return {};
|
|
} else {
|
|
tokens.shift();
|
|
if ( tokens.length &&
|
|
tokens[tokens.length - 1].type !== 'END' ) {
|
|
tokens.pop();
|
|
}
|
|
return { tokens: tokens };
|
|
}
|
|
}, // just strip it all..
|
|
true, // match the end-of-input if </noinclude> is missing
|
|
0.01, // very early in stage 1, to avoid any further processing.
|
|
'tag',
|
|
'noinclude'
|
|
);
|
|
}
|
|
|
|
// XXX: Preserve includeonly content in meta tag (data attribute) for
|
|
// round-tripping!
|
|
function IncludeOnly( manager, isInclude ) {
|
|
new TokenCollector(
|
|
manager,
|
|
function ( tokens ) {
|
|
if ( isInclude ) {
|
|
tokens.shift();
|
|
if ( tokens.length &&
|
|
tokens[tokens.length - 1].type !== 'END' ) {
|
|
tokens.pop();
|
|
}
|
|
return { tokens: tokens };
|
|
} else {
|
|
manager.env.tp( 'includeonly stripping' );
|
|
return {};
|
|
}
|
|
},
|
|
true, // match the end-of-input if </noinclude> is missing
|
|
0.01, // very early in stage 1, to avoid any further processing.
|
|
'tag',
|
|
'includeonly'
|
|
);
|
|
}
|
|
|
|
|
|
if (typeof module == "object") {
|
|
module.exports.NoInclude = NoInclude;
|
|
module.exports.IncludeOnly = IncludeOnly;
|
|
}
|