mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 17:00:10 +00:00
A collection of small bug fixes to the grammar, Cite, the Token format
converter and the HTML DOM -> WikiDom converter. The tokenizer now digests all parserTests.
This commit is contained in:
parent
730b75ca21
commit
fc41c8887c
|
@ -7,6 +7,8 @@
|
||||||
function Cite () {
|
function Cite () {
|
||||||
this.refGroups = {};
|
this.refGroups = {};
|
||||||
this.refTokens = [];
|
this.refTokens = [];
|
||||||
|
// Within ref block
|
||||||
|
this.isActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,17 +113,27 @@ Cite.prototype.onRef = function ( tokenCTX ) {
|
||||||
|
|
||||||
var token = tokenCTX.token;
|
var token = tokenCTX.token;
|
||||||
// Collect all tokens between ref start and endtag
|
// Collect all tokens between ref start and endtag
|
||||||
if ( token.type === 'TAG' && token.name.toLowerCase() === 'ref' ) {
|
if ( ! this.isActive &&
|
||||||
|
token.type === 'TAG' &&
|
||||||
|
token.name.toLowerCase() === 'ref' ) {
|
||||||
this.curRef = tokenCTX.token;
|
this.curRef = tokenCTX.token;
|
||||||
// Prepend self for 'any' token type
|
// Prepend self for 'any' token type
|
||||||
tokenCTX.dispatcher.prependListener(this.onRefCB, 'any' );
|
tokenCTX.dispatcher.prependListener(this.onRefCB, 'any' );
|
||||||
tokenCTX.token = null;
|
tokenCTX.token = null;
|
||||||
|
this.isActive = true;
|
||||||
return tokenCTX;
|
return tokenCTX;
|
||||||
} else if ( token.type === 'ENDTAG' && token.name.toLowerCase() === 'ref' ) {
|
} else if ( this.isActive &&
|
||||||
|
// Also accept really broken ref close tags..
|
||||||
|
['TAG', 'ENDTAG', 'SELFCLOSINGTAG'].indexOf(token.type) >= 0 &&
|
||||||
|
token.name.toLowerCase() === 'ref'
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.isActive = false;
|
||||||
tokenCTX.dispatcher.removeListener(this.onRefCB, 'any' );
|
tokenCTX.dispatcher.removeListener(this.onRefCB, 'any' );
|
||||||
// fall through for further processing!
|
// fall through for further processing!
|
||||||
} else {
|
} else {
|
||||||
// Inside ref block: Collect all other tokens in refTokens and abort
|
// Inside ref block: Collect all other tokens in refTokens and abort
|
||||||
|
console.log(JSON.stringify(tokenCTX.token, null, 2));
|
||||||
this.refTokens.push(tokenCTX.token);
|
this.refTokens.push(tokenCTX.token);
|
||||||
tokenCTX.token = null;
|
tokenCTX.token = null;
|
||||||
return tokenCTX;
|
return tokenCTX;
|
||||||
|
@ -287,8 +299,9 @@ Cite.prototype.onEnd = function ( tokenCTX ) {
|
||||||
// Clean up
|
// Clean up
|
||||||
this.refGroups = {};
|
this.refGroups = {};
|
||||||
this.refTokens = [];
|
this.refTokens = [];
|
||||||
|
this.isActive = false;
|
||||||
return tokenCTX;
|
return tokenCTX;
|
||||||
}
|
};
|
||||||
|
|
||||||
if (typeof module == "object") {
|
if (typeof module == "object") {
|
||||||
module.exports.Cite = Cite;
|
module.exports.Cite = Cite;
|
||||||
|
|
Loading…
Reference in a new issue