Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51682
Change subject: Updated builder-corrected-tag fixup to add placeholders always.
......................................................................
Updated builder-corrected-tag fixup to add placeholders always.
* echo "|foo" would parse to an empty string because this would
parse to a tr-token which the builder strips but leaves behind
a mw:StartTag meta-marker. findBuilderCorrectedTags function
wasn't properly processing these markers and possibly other
markers as well.
* Fixed addPlaceholderMeta helper function to be smarter and fix
this up. With this patch, this wikitext snippet now parses and
RTs correctly. There are notes in the file about possible
improvements which makes this text editable (currently VE will
likely ignore content wrapped in mw:Placeholder metas).
* 2 more wt2wt tests now green.
* Improves RT-ing of en:Drum tabs.
Change-Id: I259bd235b8b11bff706a30a13f29723c21cef892
---
M js/lib/mediawiki.DOMPostProcessor.js
1 file changed, 46 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/82/51682/1
diff --git a/js/lib/mediawiki.DOMPostProcessor.js
b/js/lib/mediawiki.DOMPostProcessor.js
index 8426339..66e70c4 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -1450,19 +1450,49 @@
}
}
- function addPlaceholderMeta( node, dp, name ) {
- var placeHolder = node.ownerDocument.createElement('meta'),
- // TODO: pass in more precise source!
- endSrc = dp.src ||
- ( DU.hasLiteralHTMLMarker(dp) ?
- '</' + name + '>' : '' );
+ function addPlaceholderMeta( node, dp, name, opts ) {
+ var src = dp.src;
- if (!endSrc && dp.tsr) {
- endSrc = env.page.src.substring(dp.tsr[0], dp.tsr[1]);
+ if (!src) {
+ if (dp.tsr) {
+ src = env.page.src.substring(dp.tsr[0],
dp.tsr[1]);
+ } else if (opts.tsr) {
+ src = env.page.src.substring(opts.tsr[0],
opts.tsr[1]);
+ } else if (DU.hasLiteralHTMLMarker(dp)) {
+ if (opts.start) {
+ src = "<" + name + ">";
+ } else if (opts.end) {
+ src = "</" + name + ">";
+ }
+ }
}
- if ( endSrc ) {
+
+ if ( src ) {
+ var placeHolder;
+
+ /**
+ * SSS FIXME: We can do better with these checks and
introducing
+ * plain text instead of a placeholder. However, in
some cases,
+ * it does introduce nowiki escaping if this src has
leading spaces
+ * that could be parsed as pres.
+ *
+ * A possibly fix for this is to wrap this in a span
with a public
+ * attribute that tells WTS that this doesn't need
escaping which
+ * would have to be cleared by VE if that text gets
edited.
+ *
+ * Another fix would be for nowiki escaping to get
smarter.
+ *
+ * But for now, leaving this note in place and using
placeholders.
+ *
+ if (opts.start && (name === 'tr' || name === 'td' ||
name === 'th')) {
+ placeHolder =
node.ownerDocument.createTextNode(src);
+ } else {
+ }
+ **/
+
+ placeHolder = node.ownerDocument.createElement('meta'),
placeHolder.setAttribute('typeof', 'mw:Placeholder');
- DU.setDataParsoid(placeHolder, {src: endSrc});
+ DU.setDataParsoid(placeHolder, {src: src});
// Insert the placeHolder
node.parentNode.insertBefore(placeHolder, node);
@@ -1562,17 +1592,20 @@
// Not found, the tag
was stripped. Insert an
// mw:Placeholder for
round-tripping
//console.log('autoinsertedEnd', c.innerHTML, c.parentNode.innerHTML);
- addPlaceholderMeta(c,
dp, expectedName);
+ addPlaceholderMeta(c,
dp, expectedName, {end: true});
}
} else if ( type === 'mw:StartTag' ) {
+ var dataStag =
c.getAttribute('data-stag'),
+ data =
dataStag.split(":"),
+ stagTsr =
data[1].split(",");
+ expectedName = data[0];
sibling = c.previousSibling;
- expectedName =
c.getAttribute('data-stag').replace(/:.*$/, '');
if (( sibling &&
sibling.nodeName.toLowerCase() !== expectedName ) ||
(!sibling &&
c.parentNode.nodeName.toLowerCase() !== expectedName ))
{
//console.log( 'start
stripped! ', expectedName, c.parentNode.innerHTML );
- addPlaceholderMeta(c,
dp, expectedName);
+ addPlaceholderMeta(c,
dp, expectedName, {start: true, tsr: stagTsr});
}
} else {
// Jump over this meta tag, but
preserve it
--
To view, visit https://gerrit.wikimedia.org/r/51682
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I259bd235b8b11bff706a30a13f29723c21cef892
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