Introduce Parsing/DOM scopes for content fragments

* Added mechanism to parse a set of tokens in its own parsing
  scope all the way to DOM (which in turn restricts token
  transformations to just that scope). This is equivalent to
  enforcing well-balanced requirements in restricted contexts
  (Ex: link content, image captions for starters). This also
  provides an option of enforcing balanced templates in certain
  contexts.

  This patch applies it to link content and image captions.
  Deleted the hacky closeUnclosedBlockTags code for dealing
  with bad HTML in captions.

* Refactored common/duplicate code out of Cite handler and
  Template handler.

* Updated DSR handling for dom-fragments which eliminates the
  warnings about cs/s dsr mismatches seen on image reuse.

  it:Dalmine used to get a bunch of DSR inconsistency warnings
  when dom-fragments were reused (reported in bug 53071) and
  are now fixed with this patch.

* There is still one big hole in DOM fragment unpacking that
  has to be fixed. This pertains to improper tag nesting that
  will be broken up by the tree builder. The DOM fragment unpacker
  has to recognize these scenarios and fix up the DOM (either
  by fixing up the final DOM or by stripping mis-nested tags
  in the DOM fragment being unpacked).

  This patch has an incomplete hack for this that addresses
  the common-use case of nested a-tags generated by wikitext
  of this form: "[http://foo.bar a [[Wikilink] here]".

Bug: 54454
Bug: 49942
Bug: 44476
Bug: 47326

Change-Id: I33ee38bc43743125b705ac821b339586593dbef7
This commit is contained in:
Subramanya Sastry 2013-09-23 18:07:29 -07:00
parent bd680c2e64
commit 167dac7979

View file

@ -7,7 +7,6 @@
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' );
@ -115,6 +114,7 @@ Ref.prototype.handleRef = function ( manager, pipelineOpts, refTok, cb ) {
pipelineType: 'text/x-mediawiki/full',
pipelineOpts: {
inTemplate: pipelineOpts.inTemplate,
noPre: true,
extTag: "ref"
},
res: [],
@ -244,9 +244,6 @@ function References(cite) {
this.reset();
}
// Inherit functionality from ExtensionHandler
coreutil.inherits(References, ExtensionHandler);
References.prototype.reset = function(group) {
if (group) {
setRefGroup(this.refGroups, group, undefined);
@ -304,30 +301,25 @@ References.prototype.handleReferences = function ( manager, pipelineOpts, refsTo
" about='", referencesId, "'",
"></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('')
var olProcessor = function(ol) {
var dp = DU.getJSONAttribute(ol, "data-parsoid", {});
dp.src = refsTok.getAttribute('source');
if (group) {
dp.group = group;
}
DU.setJSONAttribute(ol, "data-parsoid", dp);
};
// 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, referencesId), async: false });
cb({
tokens: DU.buildDOMFragmentForTokenStream(
refsTok,
buf.join(''),
manager.env,
olProcessor,
referencesId
),
async:false
});
}.bind(this);
processExtSource(manager, refsTok, {