2012-01-20 01:46:16 +00:00
|
|
|
/**
|
|
|
|
* Simple noinclude / onlyinclude implementation. Strips all tokens in
|
|
|
|
* noinclude sections.
|
|
|
|
*
|
|
|
|
* @author Gabriel Wicke <gwicke@wikimedia.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
var TokenCollector = require( './ext.util.TokenCollector.js' ).TokenCollector;
|
|
|
|
|
2012-02-11 16:43:25 +00:00
|
|
|
|
2012-01-20 22:02:23 +00:00
|
|
|
function NoInclude( manager, isInclude ) {
|
2012-01-20 01:46:16 +00:00
|
|
|
new TokenCollector(
|
|
|
|
manager,
|
|
|
|
function ( tokens ) {
|
2012-01-20 22:02:23 +00:00
|
|
|
if ( isInclude ) {
|
2012-01-31 16:50:16 +00:00
|
|
|
manager.env.tp( 'noinclude stripping' );
|
2012-01-20 22:02:23 +00:00
|
|
|
return {};
|
|
|
|
} else {
|
|
|
|
tokens.shift();
|
|
|
|
if ( tokens.length &&
|
|
|
|
tokens[tokens.length - 1].type !== 'END' ) {
|
|
|
|
tokens.pop();
|
|
|
|
}
|
|
|
|
return { tokens: tokens };
|
|
|
|
}
|
2012-01-20 01:46:16 +00:00
|
|
|
}, // 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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-02-11 16:43:25 +00:00
|
|
|
// XXX: Preserve includeonly content in meta tag (data attribute) for
|
|
|
|
// round-tripping!
|
2012-01-20 22:02:23 +00:00
|
|
|
function IncludeOnly( manager, isInclude ) {
|
2012-01-20 01:46:16 +00:00
|
|
|
new TokenCollector(
|
|
|
|
manager,
|
2012-01-20 22:02:23 +00:00
|
|
|
function ( tokens ) {
|
|
|
|
if ( isInclude ) {
|
|
|
|
tokens.shift();
|
|
|
|
if ( tokens.length &&
|
|
|
|
tokens[tokens.length - 1].type !== 'END' ) {
|
|
|
|
tokens.pop();
|
|
|
|
}
|
|
|
|
return { tokens: tokens };
|
|
|
|
} else {
|
2012-01-31 16:50:16 +00:00
|
|
|
manager.env.tp( 'includeonly stripping' );
|
2012-01-20 22:02:23 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
},
|
2012-01-20 01:46:16 +00:00
|
|
|
true, // match the end-of-input if </noinclude> is missing
|
|
|
|
0.01, // very early in stage 1, to avoid any further processing.
|
|
|
|
'tag',
|
2012-01-20 22:02:23 +00:00
|
|
|
'includeonly'
|
2012-01-20 01:46:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof module == "object") {
|
|
|
|
module.exports.NoInclude = NoInclude;
|
2012-01-20 22:02:23 +00:00
|
|
|
module.exports.IncludeOnly = IncludeOnly;
|
2012-01-20 01:46:16 +00:00
|
|
|
}
|