Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/60807
Change subject: Cleanup: Fixed some comments, formatting, removed dead code
......................................................................
Cleanup: Fixed some comments, formatting, removed dead code
* No change in functionality or parser test results.
Change-Id: I66a7b1f2a1618d0809d6783156fcc6bc89b44885
---
M js/lib/ext.Cite.js
M js/lib/mediawiki.DOMPostProcessor.js
M js/lib/mediawiki.WikitextSerializer.js
3 files changed, 42 insertions(+), 92 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/07/60807/1
diff --git a/js/lib/ext.Cite.js b/js/lib/ext.Cite.js
index 696a22e..174cf41 100644
--- a/js/lib/ext.Cite.js
+++ b/js/lib/ext.Cite.js
@@ -256,12 +256,10 @@
group = null;
}
- // Re-emit a references placeholder token
- // to be processed in post-expansion Sync phase
+ // Emit a placeholder meta for the references token
+ // so that the dom post processor can generate and
+ // emit references at this point in the DOM.
var emitPlaceholderMeta = function() {
- // Emit a placeholder meta for the references token
- // so that the dom post processor can generate and
- // emit references at this point in the DOM.
var placeHolder = new SelfclosingTagTk('meta', refsTok.attribs,
refsTok.dataAttribs);
placeHolder.setAttribute('typeof', 'mw:Ext/References');
placeHolder.setAttribute('about', '#' +
manager.env.newObjectId());
diff --git a/js/lib/mediawiki.DOMPostProcessor.js
b/js/lib/mediawiki.DOMPostProcessor.js
index 2b1927f..6bb1aa5 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -2470,12 +2470,12 @@
this.options = options;
// DOM traverser that runs before the in-order DOM handlers.
- var firstDOMHandlerPass = new DOMTraverser();
- firstDOMHandlerPass.addHandler( null, migrateDataParsoid );
+ var dataParsoidLoader = new DOMTraverser();
+ dataParsoidLoader.addHandler( null, migrateDataParsoid );
// Common post processing
this.processors = [
- firstDOMHandlerPass.traverse.bind( firstDOMHandlerPass ),
+ dataParsoidLoader.traverse.bind( dataParsoidLoader ),
handleUnbalancedTableTags,
migrateStartMetas,
//normalizeDocument,
@@ -2501,12 +2501,11 @@
var lastDOMHandler = new DOMTraverser();
lastDOMHandler.addHandler( 'a', handleLinkNeighbours.bind( null, env )
);
lastDOMHandler.addHandler( 'meta', stripMarkerMetas );
-
- var reallyLastDOMHandler = new DOMTraverser();
- reallyLastDOMHandler.addHandler( null, saveDataParsoid );
-
this.processors.push(lastDOMHandler.traverse.bind(lastDOMHandler));
-
this.processors.push(reallyLastDOMHandler.traverse.bind(reallyLastDOMHandler));
+
+ var dataParsoidSaver = new DOMTraverser();
+ dataParsoidSaver.addHandler( null, saveDataParsoid );
+ this.processors.push(dataParsoidSaver.traverse.bind(dataParsoidSaver));
}
// Inherit from EventEmitter
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index c89535e..bab9f11 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -189,9 +189,6 @@
// console.warn("---HWT---:onl:" + onNewline + ":" + text);
// tokenize the text
- // this is synchronous for now, will still need sync version later, or
- // alternatively make text processing in the serializer async
-
var prefixedText = text;
if (!onNewline) {
// Prefix '_' so that no start-of-line wiki syntax matches.
@@ -320,18 +317,37 @@
/* *********************************************************************
* Here is what the state attributes mean:
*
+ * rtTesting
+ * Are we currently running round-trip tests? If yes, then we know
+ * there won't be any edits and we more aggressively try to use original
+ * source and source flags during serialization since this is a test of
+ * Parsoid's efficacy in preserving information.
+ *
* sep
* Separator information:
* - constraints: min/max number of newlines
* - text: collected separator text from DOM text/comment nodes
* - lastSourceNode: -- to be documented --
*
+ * onSOL
+ * Is the serializer at the start of a new wikitext line?
+ *
+ * atStartOfOutput
+ * True when wts kicks off, false after the first char has been output
+ *
+ * inIndentPre
+ * Is the serializer currently handling indent-pre tags?
+ *
+ * inPHPBlock
+ * Is the serializer currently handling a tag that the PHP parser
+ * treats as a block tag?
+ *
* wteHandlerStack
- * stack of wikitext escaping handlers -- these handlers are responsible
+ * Stack of wikitext escaping handlers -- these handlers are responsible
* for smart escaping when the surrounding wikitext context is known.
*
* tplAttrs
- * tag attributes that came from templates in source wikitext -- these
+ * Tag attributes that came from templates in source wikitext -- these
* are collected upfront from the DOM from mw-marked nodes.
*
* currLine
@@ -339,9 +355,11 @@
* a "single line" of output wikitext as represented by a block node in
* the DOM.
*
- * - text : text output so far from all text nodes on the current line
+ * - firstNode: first DOM node processed on this line
+ * - text: output so far from all (unescaped) text nodes on the current line
+ * - processed: has 'text' been analyzed already?
* - hasOpenHeadingChar: does the emitted text have an "=" char in sol posn?
- * - hasOpenBrackets : does the line have bracket wikitext token pairs?
+ * - hasOpenBrackets: does the line have open left brackets?
* ********************************************************************* */
WSP.initialState = {
@@ -349,7 +367,7 @@
sep: {},
onSOL: true,
escapeText: false,
- atStartOfOutput: true,
+ atStartOfOutput: true, // SSS FIXME: Can this be done away with in some
way?
inIndentPre: false,
inPHPBlock: false,
wteHandlerStack: [],
@@ -519,24 +537,6 @@
// Make sure the initialState is never modified
Util.deepFreeze( WSP.initialState );
-var openHeading = function(v) {
- return function( state ) {
- return v;
- };
-};
-
-var closeHeading = function(v) {
- return function(state, token) {
- var prevToken = state.prevToken;
- // Deal with empty headings. Ex: <h1></h1>
- if (prevToken.constructor === pd.TagTk && prevToken.name ===
token.name) {
- return "<nowiki></nowiki>" + v;
- } else {
- return v;
- }
- };
-};
-
function escapedText(text) {
var match =
text.match(/^((?:.*?|[\r\n]+[^\r\n]|[~]{3,5})*?)((?:\r?\n)*)$/);
return ["<nowiki>", match[1], "</nowiki>", match[2]].join('');
@@ -619,8 +619,8 @@
// console.warn("---EWT:DBG1---");
return escapedText(text);
} else if (!state.onSOL) {
- // Detect if we have open brackets -- we use 'processed' flag as
- // a performance opt. to run this detection only if/when
required.
+ // Detect if we have open brackets or heading chars -- we use
'processed' flag
+ // as a performance opt. to run this detection only if/when
required.
//
// FIXME: Even so, it is reset after after every emitted text
chunk.
// Could be optimized further by figuring out a way to only test
@@ -659,10 +659,6 @@
cl.hasOpenBrackets && text.match(/^[^\[]*\]/) &&
this.wteHandlers.hasWikitextTokens(state, sol,
cl.text + text, true))
{
- // If the current line emitted so far has an open
bracket, and the current
- // piece of text has one of the pairs ^=,],]], assume
the worst and escape it.
- // NOTE: It is sufficient to escape just one of the
pairs.
-
// console.warn("---EWT:DBG2---");
return escapedText(text);
} else {
@@ -780,7 +776,6 @@
cb( "[[" + outBits.join('|') + "]]", node );
};
-
WSP._serializeTableTag = function ( symbol, endSymbol, state, token ) {
var sAttribs = this._serializeAttributes(state, token);
@@ -928,14 +923,13 @@
return rtData;
};
-
function escapeWikiLinkContentString ( contentString, state ) {
// Wikitext-escape content.
//
// When processing link text, we are no longer in newline state
// since that will be preceded by "[[" or "[" text in target wikitext.
-
state.wteHandlerStack.push(state.serializer.wteHandlers.wikilinkHandler);
state.onSOL = false;
+
state.wteHandlerStack.push(state.serializer.wteHandlers.wikilinkHandler);
var res = state.serializer.escapeWikiText(state, contentString);
state.wteHandlerStack.pop();
return res;
@@ -947,7 +941,6 @@
// check for autoInsertedStart and autoInsertedEnd attributes and
// supress openTagSrc or endTagSrc appropriately.
WSP.linkHandler = function(node, state, cb) {
- //return '[[';
// TODO: handle internal/external links etc using RDFa and dataAttribs
// Also convert unannotated html links without advanced attributes to
// external wiki links for html import. Might want to consider
converting
@@ -960,7 +953,6 @@
// Get the rt data from the token and tplAttrs
linkData = getLinkRoundTripData(node, state);
-
if ( linkData.type !== null && linkData.target.value !== null ) {
// We have a type and target info
@@ -1180,7 +1172,6 @@
'mw:DiffMarker': 1
};
-
function id(v) {
return function() {
return v;
@@ -1216,42 +1207,6 @@
// These (and inline elements) reset the default syntax to
// undefined
noHTMLSTXTags = {p: 1};
-
-// XXX refactor: move to dedicated template handler that consumes siblings
-// if (state.activeTemplateId &&
-// state.activeTemplateId === node.getAttribute("about"))
-// {
-// // skip -- template content
-// return;
-// } else {
-// state.activeTemplateId = null;
-// }
-//
-// if (!state.activeTemplateId) {
-// // Check if this node marks the start of template output
-// // NOTE: Since we are deleting all mw:Object/**/End
markers,
-// // we need not verify if it is an End marker
-// var typeofVal = node.getAttribute("typeof");
-// if (typeofVal &&
typeofVal.match(/\bmw:Object(\/[^\s]+|\b)/)) {
-// state.activeTemplateId =
node.getAttribute("about") || "";
-// var attrs = [ new pd.KV("typeof",
"mw:TemplateSource") ];
-// var dps =
node.getAttribute("data-parsoid-serialize");
-// if (dps) {
-// attrs.push(new
pd.KV("data-parsoid-serialize", dps));
-// }
-// var dummyToken = new pd.SelfclosingTagTk("meta",
-// attrs,
-// { src: this._getDOMRTInfo(node).src }
-// );
-//
-// this._serializeToken(state, dummyToken);
-// return;
-// }
-// }
-// } else if (node.nodeType !== node.COMMENT_NODE) {
-// state.activeTemplateId = null;
-// }
-//
/**
@@ -1637,7 +1592,7 @@
if (nodeName in {td:1, body:1}) {
return {min: 0, max: 1};
} else {
- return {min: 0, max:0};
+ return {min: 0, max: 0};
}
} else if (otherNode === node.previousSibling &&
// p-p transition
@@ -1657,9 +1612,9 @@
!(
DU.isBlockNode(node.parentNode) ||
otherNode.nodeValue.match(/\n(?!$)/)))))
{
- return {min:2, max:2};
+ return {min: 2, max: 2};
} else {
- return {min:1, max:2};
+ return {min: 1, max: 2};
}
},
after: function(node, otherNode) {
@@ -1700,7 +1655,6 @@
// Insert indentation
content = ' ' +
content.replace(/(\n(<!--(?:[^\-]|\-(?!\->))*\-\->)*)(?!$)/g, '$1 ' );
-
// Strip trailing separators
//var trailingSep = content.match(/\s*$/);
@@ -2088,7 +2042,6 @@
// XXX: round-trip optional whitespace / line breaks etc
return out.join(' ');
};
-
WSP._htmlElementHandler = function (node, state, cb) {
var attribKVs = DU.getAttributeKVArray(node);
--
To view, visit https://gerrit.wikimedia.org/r/60807
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I66a7b1f2a1618d0809d6783156fcc6bc89b44885
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits