Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58218
Change subject: WIP: Added --editMode option to parse.js and parserTests.js
......................................................................
WIP: Added --editMode option to parse.js and parserTests.js
* This turns off autoInserted* flags in the parser as well as
the serializer. Enabling this mode will cause more parser tests
to fail as well as add a lot more noise to roundtrip-testing.
Selective serialization automatically disables the use of these
flags. Production deploy in the live editing scenario will also
disable the flags.
* CAVEAT: Disabling autoInserted* flags in the parser also affects
the accuracy of DSR flags since the auto-inserted/deleted flags
get in the way of DSR computation. In turn, this might affect
the accuracy of selser as well.
* Running parserTests in editMode seems to lead to 25 additional
non-selser tests failing (2 wt2html, 23 wt2wt).
Change-Id: Iaa3b1bf17d8068d21d87153837ab97b61448dcda
---
M js/lib/mediawiki.DOMPostProcessor.js
M js/lib/mediawiki.SelectiveSerializer.js
M js/lib/mediawiki.WikitextSerializer.js
M js/tests/parse.js
M js/tests/parserTests.js
5 files changed, 46 insertions(+), 30 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/18/58218/1
diff --git a/js/lib/mediawiki.DOMPostProcessor.js
b/js/lib/mediawiki.DOMPostProcessor.js
index b54dadf..f46d9ad 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -1,6 +1,6 @@
-"use strict";
-
/* Perform post-processing steps on an already-built HTML DOM. */
+
+"use strict";
var events = require('events'),
Util = require('./mediawiki.Util.js').Util,
@@ -1548,7 +1548,7 @@
// and adds placeholder metas for the purposes of round-tripping.
// 2. Deletes any useless end-tag marker metas
// 3. Deletes empty nodes that is entirely builder inserted (both
start/end)
- function findDeletedStartTagsAndMore(node) {
+ function findDeletedStartTagsAndMore(node, rtTesting) {
// handle unmatched mw:StartTag meta tags
var c = node.firstChild;
while (c !== null) {
@@ -1558,16 +1558,18 @@
if (DU.hasNodeName(c, "meta")) {
var metaType = c.getAttribute("typeof");
if (metaType === "mw:StartTag") {
- var dataStag =
c.getAttribute('data-stag'),
- data =
dataStag.split(":"),
- stagTsr =
data[1].split(","),
- expectedName = data[0];
- sibling = c.previousSibling;
- if (( sibling &&
sibling.nodeName.toLowerCase() !== expectedName ) ||
- (!sibling &&
c.parentNode.nodeName.toLowerCase() !== expectedName ))
- {
- //console.log( 'start
stripped! ', expectedName, c.parentNode.innerHTML );
- addPlaceholderMeta(c,
dp, expectedName, {start: true, tsr: stagTsr});
+ if (rtTesting) {
+ var dataStag =
c.getAttribute('data-stag'),
+ data =
dataStag.split(":"),
+ stagTsr =
data[1].split(","),
+ expectedName =
data[0];
+ sibling =
c.previousSibling;
+ if (( sibling &&
sibling.nodeName.toLowerCase() !== expectedName ) ||
+ (!sibling &&
c.parentNode.nodeName.toLowerCase() !== expectedName))
+ {
+ //console.log(
'start stripped! ', expectedName, c.parentNode.innerHTML );
+
addPlaceholderMeta(c, dp, expectedName, {start: true, tsr: stagTsr});
+ }
}
deleteNode(c);
} else if (metaType === "mw:EndTag" &&
!dp.tsr) {
@@ -1580,7 +1582,7 @@
// Delete any node that was inserted as
a fixup node but has no content
deleteNode(c);
} else {
- findDeletedStartTagsAndMore(c);
+ findDeletedStartTagsAndMore(c,
rtTesting);
}
}
c = sibling;
@@ -1680,8 +1682,10 @@
}
}
- findAutoInsertedTags(document.body);
- findDeletedStartTagsAndMore(document);
+ if (!env.conf.parsoid.editMode) {
+ findAutoInsertedTags(document.body);
+ }
+ findDeletedStartTagsAndMore(document, !env.conf.parsoid.editMode);
}
// node -- node to process
diff --git a/js/lib/mediawiki.SelectiveSerializer.js
b/js/lib/mediawiki.SelectiveSerializer.js
index 5e7826d..8ddd7d1 100644
--- a/js/lib/mediawiki.SelectiveSerializer.js
+++ b/js/lib/mediawiki.SelectiveSerializer.js
@@ -385,9 +385,12 @@
* @param options.oldid {string} The revision ID you want to compare to
(defaults to latest revision)
*/
var SelectiveSerializer = function ( options ) {
- this.wts = options.wts || new WikitextSerializer( options );
+ // Set edit mode
+ this.env = options.env || { conf : { parsoid : {} } };
+ this.env.conf.parsoid = Util.clone(this.env.conf.parsoid);
+ this.env.conf.parsoid.editMode = true;
- this.env = options.env || {};
+ this.wts = options.wts || new WikitextSerializer( options );
// The output wikitext collector
this.wtChunks = [];
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index 19a46df..9d25cd8 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -268,11 +268,9 @@
* @param options {Object} List of options for serialization
*/
function WikitextSerializer( options ) {
- this.options = Util.extendProps( {
- // defaults
- }, options || {} );
-
+ this.options = options || {};
this.env = options.env;
+ this.options.rtTesting = !this.env.conf.parsoid.editMode;
this.debugging = this.env.conf.parsoid.traceFlags &&
(this.env.conf.parsoid.traceFlags.indexOf("wts") !== -1);
@@ -337,7 +335,6 @@
* ********************************************************************* */
WSP.initialState = {
- // TODO: default to false for anything that could involve edits to the
DOM
rtTesting: true,
sep: {},
atStartOfOutput: true,
@@ -2918,8 +2915,8 @@
var state = Util.extendProps({},
// Make sure these two are cloned, so we don't alter the initial
// state for later serializer runs.
- Util.clone(this.initialState),
- Util.clone(this.options)),
+ Util.clone(this.options),
+ Util.clone(this.initialState)),
serializeInfo = state.selser.serializeInfo;
// Record the serializer
diff --git a/js/tests/parse.js b/js/tests/parse.js
index 6b0a9aa..9fb5b2b 100644
--- a/js/tests/parse.js
+++ b/js/tests/parse.js
@@ -90,6 +90,11 @@
'boolean': true,
'default': false
},
+ 'editMode': {
+ description: 'Test in edit-mode (changes some parse &
serialization strategies)',
+ 'default': false,
+ 'boolean': true
+ },
'debug': {
description: 'Debug mode',
'boolean': true,
@@ -199,6 +204,7 @@
env.conf.parsoid.fetchTemplates = argv.fetchTemplates;
env.conf.parsoid.usePHPPreProcessor =
env.conf.parsoid.fetchTemplates && argv.usephppreprocessor;
env.conf.parsoid.maxDepth = argv.maxdepth ||
env.conf.parsoid.maxDepth;
+ env.conf.parsoid.editMode = argv.editMode;
Util.setDebuggingFlags( env.conf.parsoid, argv );
diff --git a/js/tests/parserTests.js b/js/tests/parserTests.js
index 9a5502b..dc0f8ff 100644
--- a/js/tests/parserTests.js
+++ b/js/tests/parserTests.js
@@ -180,11 +180,6 @@
'default': false,
'boolean': true
},
- 'use_source': {
- description: 'Use original source in wt2wt tests',
- 'boolean': true,
- 'default': true
- },
'html2html': {
description: 'Roundtrip testing: HTML(DOM) -> Wikitext
-> HTML(DOM)',
'default': false,
@@ -192,6 +187,16 @@
},
'selser': {
description: 'Roundtrip testing: Wikitext -> DOM(HTML)
-> Wikitext (with selective serialization)',
+ 'default': false,
+ 'boolean': true
+ },
+ 'use_source': {
+ description: 'Use original source in wt2wt tests',
+ 'boolean': true,
+ 'default': true
+ },
+ 'editMode': {
+ description: 'Test in edit-mode (changes some parse &
serialization strategies)',
'default': false,
'boolean': true
},
@@ -1274,6 +1279,7 @@
console.warn("ERROR: " + e);
console.error( e.stack );
};
+ this.env.conf.parsoid.editMode = options.editMode;
Util.setDebuggingFlags( this.env.conf.parsoid, options );
options.modes = [];
if ( options.wt2html ) {
--
To view, visit https://gerrit.wikimedia.org/r/58218
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa3b1bf17d8068d21d87153837ab97b61448dcda
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