mediawiki-extensions-Cite/js/lib/ext.Cite.js

476 lines
13 KiB
JavaScript
Raw Normal View History

Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
/* ----------------------------------------------------------------------
* This file implements <ref> and <references> extension tag handling
* natively in Parsoid.
* ---------------------------------------------------------------------- */
"use strict";
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
var Util = require( './mediawiki.Util.js' ).Util,
DU = require( './mediawiki.DOMUtils.js').DOMUtils,
coreutil = require('util'),
ExtensionHandler = require('./ext.core.ExtensionHandler.js').ExtensionHandler,
defines = require('./mediawiki.parser.defines.js'),
$ = require( './fakejquery' );
// define some constructor shortcuts
var KV = defines.KV,
SelfclosingTagTk = defines.SelfclosingTagTk;
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
// FIXME: Move out to some common helper file?
// Helper function to process extension source
function processExtSource(manager, extToken, opts) {
var extSrc = extToken.getAttribute('source'),
tagWidths = extToken.dataAttribs.tagWidths,
content = extSrc.substring(tagWidths[0], extSrc.length - tagWidths[1]);
// FIXME: SSS: This stripping maybe be unecessary after all.
//
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
// FIXME: Should this be specific to the extension
//
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
// or is it okay to do this unconditionally for all?
// Right now, this code is run only for ref and references,
// so not a real problem, but if this is used on other extensions,
// requires addressing.
//
// Strip all leading white-space
var wsMatch = content.match(/^(\s*)((?:.|\n)*)$/),
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
leadingWS = wsMatch[1];
// Update content to normalized form
content = wsMatch[2];
if (!content || content.length === 0) {
opts.emptyContentCB(opts.res);
} else {
// Pass an async signal since the ext-content is not processed completely.
opts.parentCB({tokens: opts.res, async: true});
// Pipeline for processing ext-content
var pipeline = manager.pipeFactory.getPipeline(
opts.pipelineType,
Util.extendProps({}, opts.pipelineOpts, {
wrapTemplates: true
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
})
);
// Set source offsets for this pipeline's content
var tsr = extToken.dataAttribs.tsr;
pipeline.setSourceOffsets(tsr[0]+tagWidths[0]+leadingWS.length, tsr[1]-tagWidths[1]);
// Set up provided callbacks
if (opts.chunkCB) {
pipeline.addListener('chunk', opts.chunkCB);
}
if (opts.endCB) {
pipeline.addListener('end', opts.endCB);
}
if (opts.documentCB) {
pipeline.addListener('document', opts.documentCB);
}
// Off the starting block ... ready, set, go!
pipeline.process(content);
}
}
/**
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
* Simple token transform version of the Ref extension tag
*
* @class
* @constructor
*/
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
function Ref(cite) {
this.cite = cite;
this.reset();
}
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
/**
* Reset state before each top-level parse -- this lets us share a pipeline
* to parse unrelated pages.
*/
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
Ref.prototype.reset = function() { };
/**
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
* Handle ref tokens
*/
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
Ref.prototype.handleRef = function ( manager, pipelineOpts, refTok, cb ) {
// Nested <ref> tags are not supported
if (!pipelineOpts.inTagRef && pipelineOpts.extTag === "ref" && pipelineOpts.wrapTemplates) {
cb({ tokens: [refTok.getAttribute("source")] });
return;
}
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
var inReferencesExt = pipelineOpts.extTag === "references",
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
refOpts = $.extend({ name: null, group: null }, Util.KVtoHash(refTok.getAttribute("options"))),
about = inReferencesExt ? '' : manager.env.newAboutId(),
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
finalCB = function(toks, content) {
// Marker meta with ref content
var da = Util.clone(refTok.dataAttribs);
// Clear stx='html' so that sanitizer doesn't barf
da.stx = undefined;
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
toks.push(new SelfclosingTagTk( 'meta', [
Add capability for DOM-based template expansion, and use DOM fragments for extensions This patch adds the capability to expand individual transclusions all the way to DOM, which enforces properly nested templates. This is also needed for DOM-based template re-expansion, which the VE folks would like to use for template editing. In normal parsing, DOM-based expansion is currently disabled by default for transclusions, and enabled by default for extensions. The decision whether to balance a particular transclusion can be based on a statistics-based classification of templates into balanced and unbalanced ones. The advantage of this approach is consistency in behavior for old revisions. Another alternative is to wrap unbalanced transclusions into <domparse> tags which disable DOM-based parsing for all transclusions in its content. This has the advantage that all special cases can be handled after tag insertion, and that balancing could also be enforced in the PHP parser using an extension. Other major changes: * Renamed transclusion content typeof from mw:Object/Template to mw:Transclusion * Renamed extension typeof from mw:Object/Extensions/foo to mw:Extension/foo and switched Cite to use lower-case ref/references too Other minor changes: * Only apply template encapsulation algorithm on DOM to mw:Transclusion and mw:Param objects, and no longer to all mw:Object/* elements. We should probably switch to a more explicit encapsulation type instead. Maybe something like mw:EncapStart/Transclusion and mw:EncapEnd/Transclusion instead of the current mw:Transclusion and mw:Transclusion/End, so that stripping those metas out selectively is easy? * Changed the DOMTraverser logic to let handlers explicitly return the next element to handle. Useful when several siblings are handled, as is the case for the fragment unwrapper for example, and avoids some cases where deleted nodes were still being processed. * Changed Cite to use mw:Extension/Ref{,erences} as all other extensions. * Make sure we round-trip gallery when the PHP preprocessor is not used Five parsoid-specific wt2html tests are failing due to the typeof change. They will be fine once those tests are adjusted. For now, adding them to parser tests blacklist. TODO: * Switch the Cite extension to the generic DOMFragment mechanism instead of marker tokens. Change-Id: I64b560a12695256915d2196d0646347381400e80
2013-05-16 22:23:05 +00:00
new KV('typeof', 'mw:Extension/ref/Marker'),
new KV('about', about),
new KV('group', refOpts.group || ''),
new KV('name', refOpts.name || ''),
new KV('content', content || ''),
new KV('skiplinkback', inReferencesExt ? 1 : 0)
], da));
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
// All done!
cb({tokens: toks, async: false});
};
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
processExtSource(manager, refTok, {
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
// Full pipeline for processing ref-content
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
pipelineType: 'text/x-mediawiki/full',
pipelineOpts: {
inTagRef: refTok.getAttribute("inTagRef"),
extTag: "ref"
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
},
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
res: [],
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
parentCB: cb,
emptyContentCB: finalCB,
documentCB: function(refContentDoc) {
finalCB([], refContentDoc.body.innerHTML);
}
});
};
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
/**
* Helper class used by <references> implementation
*/
function RefGroup(group) {
this.name = group || '';
this.refs = [];
this.indexByName = {};
}
RefGroup.prototype.add = function(refName, about, skipLinkback) {
// NOTE: prefix name with "ref:" before using it as a property key
// This is to avoid overwriting predefined keys like 'constructor'
var ref, indexKey = "ref:" + refName;
if (refName && this.indexByName[indexKey]) {
ref = this.indexByName[indexKey];
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
} else {
var n = this.refs.length,
refKey = (1+n) + '';
if (refName) {
refKey = refName + '-' + refKey;
}
ref = {
about: about,
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
content: null,
group: this.name,
groupIndex: (1+n), // FIXME -- this seems to be wiki-specific
index: n,
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
key: refKey,
linkbacks: [],
name: refName,
target: 'cite_note-' + refKey
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
};
this.refs[n] = ref;
if (refName) {
this.indexByName[indexKey] = ref;
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
}
}
if (!skipLinkback) {
ref.linkbacks.push('cite_ref-' + ref.key + '-' + ref.linkbacks.length);
}
return ref;
};
RefGroup.prototype.renderLine = function(refsList, ref) {
var ownerDoc = refsList.ownerDocument,
arrow = ownerDoc.createTextNode('↑'),
li, a;
// Generate the li and set ref content first, so the HTML gets parsed.
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
// We then append the rest of the ref nodes before the first node
li = ownerDoc.createElement('li');
DU.addAttributes(li, {
'about': "#" + ref.target,
'id': ref.target
});
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
li.innerHTML = ref.content;
var contentNode = li.firstChild;
// 'mw:referencedBy' span wrapper
var span = ownerDoc.createElement('span');
span.setAttribute('rel', 'mw:referencedBy');
li.insertBefore(span, contentNode);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
// Generate leading linkbacks
if (ref.linkbacks.length === 1) {
a = ownerDoc.createElement('a');
DU.addAttributes(a, {
'href': '#' + ref.linkbacks[0]
});
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
a.appendChild(arrow);
span.appendChild(a);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
} else {
span.appendChild(arrow);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
$.each(ref.linkbacks, function(i, linkback) {
a = ownerDoc.createElement('a');
DU.addAttributes(a, {
'href': '#' + ref.linkbacks[i]
});
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
a.appendChild(ownerDoc.createTextNode(ref.groupIndex + '.' + i));
// Separate linkbacks with a space
span.appendChild(ownerDoc.createTextNode(' '));
span.appendChild(a);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
});
}
// Space before content node
li.insertBefore(ownerDoc.createTextNode(' '), contentNode);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
// Add it to the ref list
refsList.appendChild(li);
};
// NOTE: prefix name with "refgroup:" before using it as a property key
// This is to avoid overwriting predefined keys like 'constructor'
function setRefGroup(refGroups, groupName, group) {
refGroups["refgroup:" + groupName] = group;
}
function getRefGroup(refGroups, groupName, allocIfMissing) {
groupName = groupName || '';
var key = "refgroup:" + groupName;
if (!refGroups[key] && allocIfMissing) {
setRefGroup(refGroups, groupName, new RefGroup(groupName));
}
return refGroups[key];
}
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
function References(cite) {
this.cite = cite;
this.reset();
}
// Inherit functionality from ExtensionHandler
coreutil.inherits(References, ExtensionHandler);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
References.prototype.reset = function(group) {
if (group) {
setRefGroup(this.refGroups, group, undefined);
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
} else {
this.refGroups = {};
}
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
};
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
/**
* Sanitize the references tag and convert it into a meta-token
*/
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
References.prototype.handleReferences = function ( manager, pipelineOpts, refsTok, cb ) {
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
refsTok = refsTok.clone();
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
// group is the only recognized option?
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
var refsOpts = Util.KVtoHash(refsTok.getAttribute("options")),
group = refsOpts.group;
if ( group && group.constructor === Array ) {
// Array of tokens, convert to string.
group = Util.tokensToString(group);
}
// Point invalid / empty groups to null
if ( ! group ) {
group = null;
}
// Emit a marker mw:DOMFragment for the references
// token so that the dom post processor can generate
// and emit references at this point in the DOM.
var emitReferencesFragment = function() {
var about = manager.env.newAboutId(),
type = refsTok.getAttribute('typeof');
var buf = [
"<ol class='references'",
" typeof='", "mw:Extension/references", "'",
" about='", about, "'",
"></ol>"
];
var wrapperDOM = Util.parseHTML(buf.join('')).body.childNodes,
ol = wrapperDOM[0];
var dp = DU.getJSONAttribute(ol, "data-parsoid", {});
dp.src = refsTok.getAttribute('source');
if (group) {
dp.group = group;
}
DU.setJSONAttribute(ol, "data-parsoid", dp);
var expansion = {
nodes: wrapperDOM,
html: wrapperDOM.map(function(n) { return n.outerHTML; }).join('')
};
// TemplateHandler wants a manager property
//
// FIXME: Seems silly -- maybe we should move encapsulateExpansionHTML
// into Util and pass env into it .. can avoid extending ExtensionHandler
// as well.
this.manager = manager;
cb({ tokens: this.encapsulateExpansionHTML(refsTok, expansion), async: false });
}.bind(this);
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
processExtSource(manager, refsTok, {
// Partial pipeline for processing ref-content
// Expand till stage 2 so that all embedded
// ref tags get processed
pipelineType: 'text/x-mediawiki',
pipelineOpts: {
extTag: "references",
wrapTemplates: pipelineOpts.wrapTemplates
},
res: [],
parentCB: cb,
emptyContentCB: emitReferencesFragment,
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
chunkCB: function(chunk) {
// Extract ref-content tokens and discard the rest
var res = [];
for (var i = 0, n = chunk.length; i < n; i++) {
var t = chunk[i];
if (t.constructor === SelfclosingTagTk &&
t.name === 'meta' &&
Add capability for DOM-based template expansion, and use DOM fragments for extensions This patch adds the capability to expand individual transclusions all the way to DOM, which enforces properly nested templates. This is also needed for DOM-based template re-expansion, which the VE folks would like to use for template editing. In normal parsing, DOM-based expansion is currently disabled by default for transclusions, and enabled by default for extensions. The decision whether to balance a particular transclusion can be based on a statistics-based classification of templates into balanced and unbalanced ones. The advantage of this approach is consistency in behavior for old revisions. Another alternative is to wrap unbalanced transclusions into <domparse> tags which disable DOM-based parsing for all transclusions in its content. This has the advantage that all special cases can be handled after tag insertion, and that balancing could also be enforced in the PHP parser using an extension. Other major changes: * Renamed transclusion content typeof from mw:Object/Template to mw:Transclusion * Renamed extension typeof from mw:Object/Extensions/foo to mw:Extension/foo and switched Cite to use lower-case ref/references too Other minor changes: * Only apply template encapsulation algorithm on DOM to mw:Transclusion and mw:Param objects, and no longer to all mw:Object/* elements. We should probably switch to a more explicit encapsulation type instead. Maybe something like mw:EncapStart/Transclusion and mw:EncapEnd/Transclusion instead of the current mw:Transclusion and mw:Transclusion/End, so that stripping those metas out selectively is easy? * Changed the DOMTraverser logic to let handlers explicitly return the next element to handle. Useful when several siblings are handled, as is the case for the fragment unwrapper for example, and avoids some cases where deleted nodes were still being processed. * Changed Cite to use mw:Extension/Ref{,erences} as all other extensions. * Make sure we round-trip gallery when the PHP preprocessor is not used Five parsoid-specific wt2html tests are failing due to the typeof change. They will be fine once those tests are adjusted. For now, adding them to parser tests blacklist. TODO: * Switch the Cite extension to the generic DOMFragment mechanism instead of marker tokens. Change-Id: I64b560a12695256915d2196d0646347381400e80
2013-05-16 22:23:05 +00:00
/^mw:Extension\/ref\/Marker$/.test(t.getAttribute('typeof')))
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
{
res.push(t);
}
}
// Pass along the ref toks
cb({ tokens: res, async: true });
},
endCB: emitReferencesFragment
Updated native <ref> and <references> tag implementations. * Updated native implementations of the <ref> and <references> tag implementations of the cite extension. * <references> tag was not being processed properly by Parsoid. This led to lost references on the BO page. This patch fixes it which fills out references and more closely matches output en:WP. * Extracted extension content processing code into a helper and reused it for both <ref> and <references> handler. - Leading ws-only lines are unconditionally stripped. Is this accurate or is this extension-specific? Given that this code is right now tied to <ref> and <references> tag, this is not yet a problem, but if made more generic, this issue has to be addressed. * PreHandler should not run when processing the refs-tag. Right now, this is a hard check in the pre-handler. Probably worth making this more generic by letting every stage in the pipeline get a chance at turning themselves on/off based on the extension being processed by the pipeline (can use the _applyToStage fn. on ParserPipeline). TO BE DONE. * <ref> extension needs to be reset after each <references> tag is processed to duplicate behavior of existing cite extension. TO BE DONE. * Updated refs group index to start at 1. * No change in parser tests. References section output on the en:Barack Obama page now more closely matches the refs output on enwp. * In addition to the en:BO page, the following wikitext was used to fix bugs and test the implementation. CMD: "node parse --extensions ref,references < /tmp/test" ---------------------------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> ---------------------------------------------- Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-26 00:40:20 +00:00
});
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
};
References.prototype.extractRefFromNode = function(node) {
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
var group = node.getAttribute("group"),
refName = node.getAttribute("name"),
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
about = node.getAttribute("about"),
skipLinkback = node.getAttribute("skiplinkback") === "1",
refGroup = getRefGroup(this.refGroups, group, true),
ref = refGroup.add(refName, about, skipLinkback),
nodeType = (node.getAttribute("typeof") || '').replace(/mw:Extension\/ref\/Marker/, '');
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
// Add ref-index linkback
if (!skipLinkback) {
var doc = node.ownerDocument,
span = doc.createElement('span'),
content = node.getAttribute("content"),
dataMW = node.getAttribute('data-mw');
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
if (!dataMW) {
dataMW = JSON.stringify({
'name': 'ref',
// Dont set body if this is a reused reference
// like <ref name='..' /> with empty content.
'body': content ? { 'html': content } : undefined,
'attrs': {
// Dont emit empty keys
'group': group || undefined,
'name': refName || undefined
}
});
}
DU.addAttributes(span, {
'about': about,
'class': 'reference',
'data-mw': dataMW,
'id': ref.linkbacks[ref.linkbacks.length - 1],
'rel': 'dc:references',
'typeof': nodeType
});
DU.addTypeOf(span, "mw:Extension/ref");
Add capability for DOM-based template expansion, and use DOM fragments for extensions This patch adds the capability to expand individual transclusions all the way to DOM, which enforces properly nested templates. This is also needed for DOM-based template re-expansion, which the VE folks would like to use for template editing. In normal parsing, DOM-based expansion is currently disabled by default for transclusions, and enabled by default for extensions. The decision whether to balance a particular transclusion can be based on a statistics-based classification of templates into balanced and unbalanced ones. The advantage of this approach is consistency in behavior for old revisions. Another alternative is to wrap unbalanced transclusions into <domparse> tags which disable DOM-based parsing for all transclusions in its content. This has the advantage that all special cases can be handled after tag insertion, and that balancing could also be enforced in the PHP parser using an extension. Other major changes: * Renamed transclusion content typeof from mw:Object/Template to mw:Transclusion * Renamed extension typeof from mw:Object/Extensions/foo to mw:Extension/foo and switched Cite to use lower-case ref/references too Other minor changes: * Only apply template encapsulation algorithm on DOM to mw:Transclusion and mw:Param objects, and no longer to all mw:Object/* elements. We should probably switch to a more explicit encapsulation type instead. Maybe something like mw:EncapStart/Transclusion and mw:EncapEnd/Transclusion instead of the current mw:Transclusion and mw:Transclusion/End, so that stripping those metas out selectively is easy? * Changed the DOMTraverser logic to let handlers explicitly return the next element to handle. Useful when several siblings are handled, as is the case for the fragment unwrapper for example, and avoids some cases where deleted nodes were still being processed. * Changed Cite to use mw:Extension/Ref{,erences} as all other extensions. * Make sure we round-trip gallery when the PHP preprocessor is not used Five parsoid-specific wt2html tests are failing due to the typeof change. They will be fine once those tests are adjusted. For now, adding them to parser tests blacklist. TODO: * Switch the Cite extension to the generic DOMFragment mechanism instead of marker tokens. Change-Id: I64b560a12695256915d2196d0646347381400e80
2013-05-16 22:23:05 +00:00
span.data = {
parsoid: {
src: node.data.parsoid.src,
dsr: node.data.parsoid.dsr
}
};
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
// refIndex-span
node.parentNode.insertBefore(span, node);
// refIndex-a
var refIndex = doc.createElement('a');
refIndex.setAttribute('href', '#' + ref.target);
refIndex.appendChild(doc.createTextNode(
'[' + ((group === '') ? '' : group + ' ') + ref.groupIndex + ']'
));
span.appendChild(refIndex);
}
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
// This effectively ignores content from later references with the same name.
// The implicit assumption is that that all those identically named refs. are
// of the form <ref name='foo' />
if (!ref.content) {
ref.content = node.getAttribute("content");
}
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
};
References.prototype.insertReferencesIntoDOM = function(refsNode) {
var about = refsNode.getAttribute('about'),
group = refsNode.data.parsoid.group || '',
src = refsNode.data.parsoid.src || '', // fall back to '' so we don't crash
// Extract ext-source for <references>..</references> usage
Enable wrapped extensions to parse and RT correctly * Temporarily hacked sanitizer to pass through typeof attribute so that mw:DOMFragment wrapper for extension tags can get to the DOM post processor and get unwrapped. * Implemented getArgDict for the extension handler since data-mw for extensions has a different form than that for templates. * Extracted common functionality into Util.js and used it in Cite.js and ExtensionHandler.js * Tested with timeline extension (test snippet below) and verified that it parses and RTs both with editMode true and false. TODO: Long overdue. Extension testing. -------- <timeline> ImageSize = width:250 height:200 PlotArea = left:40 right:10 top:10 bottom:20 TimeAxis = orientation:horizontal AlignBars = justify Colors = id:gray1 value:gray(0.9) DateFormat = yyyy Period = from:1960 till:2010 ScaleMajor = unit:year increment:10 start:1960 PlotData = bar:3000 color:gray1 width:1 from:start till:end bar:2000 color:gray1 from:start till:end bar:1000 color:gray1 from:start till:end bar:0 color:gray1 LineData = layer:front points:(48,96)(84,111) color:blue width:2 #1962 tot 1968. Inwonertal 1962: 1348 1968: 1610 points:(84,111)(100,112) color:blue width:2 #1975: 1627 points:(100,112)(128,116) color:blue width:2 #1982: 1699 points:(128,116)(160,135) color:blue width:2 #1990: 2036 points:(160,135)(196,146) color:blue width:2 #1999: 2217 points:(196,146)(228,158) color:blue width:2 #2004/5 </timeline> -------- Change-Id: Ia8d2f82e893047e2447cf809e04cc7f508f5899b
2013-06-06 00:00:41 +00:00
body = Util.extractExtBody("references", src).trim(),
refGroup = getRefGroup(this.refGroups, group);
var dataMW = refsNode.getAttribute('data-mw');
if (!dataMW) {
dataMW = JSON.stringify({
'name': 'references',
// We'll have to output data-mw.body.extsrc in
// scenarios where original wikitext was of the form:
// "<references> lot of refs here </references>"
// Ex: See [[en:Barack Obama]]
'body': body.length > 0 ? { 'extsrc': body } : undefined,
'attrs': {
// Dont emit empty keys
'group': group || undefined
}
});
}
refsNode.setAttribute('data-mw', dataMW);
if (refGroup) {
refGroup.refs.map(refGroup.renderLine.bind(refGroup, refsNode));
Extension handling rewrite + cite extension refactoring. Tokenization ------------ * Fixed tokenizer to correctly parse extension tags in different contexts: with start and end tags, in self-closing tag mode, and to correctly handle scenarios when the exension end-tag is followed by a '#' (the special char used to skip over extension content). * Removed the distinction in the tokenizer between installed extensions and natively supported extension tags (<ref> and <references> for ex.). They all tokenize and get processed identically and get handled by different paths in the extension handler. * Template and TemplateArg tokens now carry tpl. transclusion source alongwith them since tsr information will not be accurate when they show up in extension contexts that in turn showed up in template context that were expanded by the php preprocessor. Ex: {{echo|<ref>{{echo|foo}}</ref>}} The tsr for the ref-tag will correspond to the template-source of the echo-template, NOT the original top-level page. So, env.page.src.substring(..) will return incorrect source for the innermost {{echo|foo}}. This fix of carrying along tpl transclusion source in the token itself eliminates this problem. Knowledge of native extensions ------------------------------ * Natively implemented extension tags (<ref> and <references>) are hardcoded in env.conf.parsoid. At some point, it would be good to have a registration mechanism for parsoid-native extensions. Extension handling ------------------ * Extracted extension handling out of the template handler into its own handler class. Right now, this class inherits from the template handler in order to be able to reuse a lot of the expansion and encapsulation functionality currently in the Template Handler. * This handler now handles extensions that are: (a) natively implemented and registered with Parsoid. (b) implemented as a PHP extension and expanded by relying on the PHP preprocessor. For (a), it uses information from env.conf.parsoid to find ext-handlers for natively implemented ext-tags. However, this can be cleaned up at some point by making available a registration mechanism. Cite/Ref/References ------------------- * Reworked the cite handler to split up ref-token processing and references token processing. * The handler now processes ref-tokens, parses content all the way to html output and encapsulates the html in an attribute of a meta-token that serves as a placeholder for where the ref-token occured. * References are handled as a DOM post-pass where these meta placeholder tokens are collected, content extracted from the attribute and spit out at the site of a references tag. The DOM walking is in DOMPostProcessor.js, but the actual processing is part of the Cite.js to keep all cite extension handling code in one place. Parser pipeline --------------- * Restructured parser pipeline recipes based on changes to Cite, TemplateHandler, and ExtensionHandler. * Added a couple functions to the parser pipeline: 1. resetState to reset state before starting a new top-level parse when pipelines are reused across top-level parses (ex: parser tests) 2. setSourceOffsets to set start/end offsets of the source being handled by the pipeline. This is required to correctly set tsr values when extension content (which is a substring of original top-level text) is parsed in its own pipeline. Other fixes ----------- * Removed env parameter from the Params object since it was not being used and seemed like unnecessary state propagation. * Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code in the tokenizer that converts "\n" in text to NlTks. * Cleanup of Util.shiftTokenTSR. * ext.util.TokenCollection is now no longer used by anything. Added a FIXME and left around in case we are able to improve tokenizing and handling of *include* tags that can eliminate the need for the messy TokenAndAttrCollector. Test results ------------ * No change in parser tests results. * Tested with a few different files. - en:BO page seems to be parsed about 10% faster than before (needs verification). - Referencs on the en:BO page seem to be more accurate than before. Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-09 00:07:59 +00:00
}
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
// reset
this.reset(group);
};
/**
* Native Parsoid implementation of the Cite extension
* that ties together <ref> and <references>
*/
var Cite = function() {
this.ref = new Ref(this);
this.references = new References(this);
};
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
Cite.prototype.resetState = function(group) {
this.ref.reset();
Moved ref-index generation to DOM post-pass * When I last fixed Cite in commit 0164b846, I didn't take it all the way through. I was assigning ref indexes in the async pipeline which is incorrect since ref-tokens and references-tokens should be processed in the same order as they show up in the input. * I now moved ref-index assignment to the DOM post processor phase where they always belonged. * Fixed references and cite reset functions to only reset a specific group, if necessary. * Pipelines processing template transclusions should propagate the extension tag if the transclusion showed up in the context of extension source so that any extension-specific constraints are respected. (Ex: ref-tags in reference-extension context are handled differently -- and this should continue to be true even when the tags show up via transcluded content) * These fixes were tested on the following snippet from 0164b846. Where this snippet was generating buggy output earlier, it is now being handled correctly. --------------------------- X1<ref name="x" /> X2<ref name="x" /> <references> <ref name="x">x</ref> </references> Y<ref name="y">{{echo|y}}</ref> Z<ref name="z" /> <references> {{echo|<ref name="z">z</ref>}} </references> A<ref name="a">a</ref> B<ref name="b" /> <references> {{echo|<ref name="b">b</ref>}} </references> C<ref name="c">c</ref> D<ref name="d" /> <references> <ref name="d">{{echo|d}}</ref> </references> --------------------------- X1<ref name="x" /> X2<ref name="x" /> Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-24 19:09:08 +00:00
this.references.reset(group);
};
if (typeof module === "object") {
module.exports.Cite = Cite;
}