GWicke has submitted this change and it was merged.

Change subject: Bug fix serializing wiki elements nested in html elements
......................................................................


Bug fix serializing wiki elements nested in html elements

* The following wikitext snippet would not serialize the newly
  inserted wikilink as [[Foo]].  It would instead serialize into
  a HTML a-tag instead.

<small data-parsoid="{&quot;stx&quot;:&quot;html&quot;}"><a rel="mw:WikiLink" 
href="Foo">Foo</a></small>

* Reduced test case based on the following bug report in /mnt/bugs on
  parsoid.wmflabs.org

  2013-06-03T09%3A48%3A14.774Z-Le_Prix_du_silence_(film%252C_2008)

* No change in parser test results
  TODO: html2wt tests needed for new content

Change-Id: I7f9b7cf4dd7c1fadaa48ea99f3f1e19a5190afd6
---
M js/lib/mediawiki.DOMUtils.js
M js/lib/mediawiki.WikitextSerializer.js
2 files changed, 14 insertions(+), 9 deletions(-)

Approvals:
  GWicke: Verified; Looks good to me, approved



diff --git a/js/lib/mediawiki.DOMUtils.js b/js/lib/mediawiki.DOMUtils.js
index 4c50893..b94c133 100644
--- a/js/lib/mediawiki.DOMUtils.js
+++ b/js/lib/mediawiki.DOMUtils.js
@@ -135,8 +135,8 @@
                try {
                        return JSON.parse(attVal);
                } catch(e) {
-                       console.warn('ERROR: Could not decode attribute ' +
-                                       name + ' on node ' + n);
+                       console.warn('ERROR: Could not decode attribute-val ' + 
attVal +
+                                       ' for ' + name + ' on node ' + 
n.outerHTML);
                        return defaultVal !== undefined ? defaultVal : {};
                }
        },
@@ -305,6 +305,10 @@
                return dp.stx === 'html';
        },
 
+       isNewElt: function(n) {
+               return n.getAttribute('data-parsoid') === null;
+       },
+
        isLiteralHTMLNode: function(n) {
                return this.hasLiteralHTMLMarker(this.getDataParsoid(n));
        },
diff --git a/js/lib/mediawiki.WikitextSerializer.js 
b/js/lib/mediawiki.WikitextSerializer.js
index 9cf34d1..2529c2f 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -2705,13 +2705,15 @@
                }
        }
 
+       // If parent node is a list or table tag in html-syntax, then serialize
+       // new elements in html-syntax rather than wiki-syntax.
        if (dp.stx === 'html' ||
-                       ( node.getAttribute('data-parsoid') === null &&
-                         // SSS FIXME: if we get to the root, it wont have a 
parent
-                         // But, why are we getting to the root?
-                         nodeName !== 'meta' && node.parentNode &&
-                         node.parentNode.data &&
-                         node.parentNode.data.parsoid.stx === 'html' ) )
+               (DU.isNewElt(node) && node.parentNode &&
+               node.parentNode.data && node.parentNode.data.parsoid.stx === 
'html' &&
+               ((DU.isList(node.parentNode) && DU.isListElt(node)) ||
+                (node.parentNode.nodeName in {TABLE:1, TBODY:1, TH:1, TR:1} &&
+                 node.nodeName in {TBODY:1, CAPTION:1, TH:1, TR:1, TD:1}))
+               ))
        {
                return {handle: self._htmlElementHandler.bind(self)};
        } else if (self.tagHandlers[nodeName]) {
@@ -2726,7 +2728,6 @@
                return {handle: self._htmlElementHandler.bind(self)};
        }
 };
-
 
 /**
  * Serialize the content of a text node

-- 
To view, visit https://gerrit.wikimedia.org/r/67467
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7f9b7cf4dd7c1fadaa48ea99f3f1e19a5190afd6
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to