Arlolra has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/328444 )

Change subject: T143183: Extensions take precedence over templates
......................................................................

T143183: Extensions take precedence over templates

Change-Id: I85fd4d1273aff632abf3cf54fc4ba8293cae5f71
---
M lib/wt2html/pegTokenizer.pegjs
M lib/wt2html/tokenizer.utils.js
M tests/parserTests.txt
3 files changed, 24 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/44/328444/1

diff --git a/lib/wt2html/pegTokenizer.pegjs b/lib/wt2html/pegTokenizer.pegjs
index f487a3c..381b7ad 100644
--- a/lib/wt2html/pegTokenizer.pegjs
+++ b/lib/wt2html/pegTokenizer.pegjs
@@ -119,6 +119,9 @@
                 constants.HTML.BlockTags.has(uName) && !ignoredExtTag :
                 constants.HTML.HTML5Tags.has(uName) || 
constants.HTML.OlderHTMLTags.has(uName);
 
+        // WARNING: Be careful to pop this when `isXMLTag` is used.
+        stops.push('extTag', isInstalledExt);
+
         return isHtmlTag || isInstalledExt || isIncludeTag;
     };
 
@@ -1220,14 +1223,15 @@
       // should not be parsed as <th>/<td>".
       return stops.push('tableCellArg', false);
     }
-    "<"
-    end:"/"? name:$(tn:tag_name & { return isXMLTag(tn, false); })
+    "<" end:"/"?
+    name:$(tn:tag_name & { return isXMLTag(tn, false); })
     attribs:generic_newline_attributes
     space_or_newline* // No need to preserve this -- canonicalize on RT via 
dirty diff
     selfclose:"/"?
     bad_ws:space* // No need to preserve this -- canonicalize on RT via dirty 
diff
     ">" {
         stops.pop('tableCellArg');
+        stops.pop('extTag');
 
         var lcName = name.toLowerCase();
         var isVoidElt = Util.isVoidElement(lcName) ? true : null;
@@ -1252,6 +1256,7 @@
 
         return maybeExtensionTag(res);
     }
+    / "<" "/"? tag_name & { stops.pop('extTag'); return false; }
     / & { return stops.pop('tableCellArg'); }
 
 /*
@@ -1267,9 +1272,11 @@
     space_or_newline*
     selfclose:"/"?
     ">" {
+      stops.pop('extTag');
       var t = tu.buildXMLTag(name, name.toLowerCase(), attribs, end, 
selfclose, tsrOffsets());
       return [maybeExtensionTag(t)];
     }
+    / "<" "/"? tag_name & { stops.pop('extTag'); return false; }
 
 // A generic attribute that can span multiple lines.
 generic_newline_attribute
diff --git a/lib/wt2html/tokenizer.utils.js b/lib/wt2html/tokenizer.utils.js
index 9bbd1bb..c09ed65 100644
--- a/lib/wt2html/tokenizer.utils.js
+++ b/lib/wt2html/tokenizer.utils.js
@@ -182,7 +182,8 @@
                                                        .test(input.substr(pos 
+ 1)))
                                );
                        case '|':
-                               return stops.onStack('templateArg') ||
+                               return (stops.onStack('templateArg') &&
+                                               !stops.onStack('extTag')) ||
                                        stops.onStack('tableCellArg') ||
                                        stops.onStack('linkdesc') ||
                                        (stops.onStack('table') && (
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 7703d28..d25c251 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -6465,6 +6465,19 @@
 <span typeof="mw:Transclusion" 
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"ho\">ha&lt;/div>"}},"i":0}}]}'>ho">ha</span>
 !! end
 
+!! test
+Break on | in extension attribute in template
+!! wikitext
+{{echo|1=<ref class="hi
+|ho">ha</ref>}}
+
+<references />
+!! html/parsoid
+<p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" 
typeof="mw:Transclusion  mw:Extension/ref" 
data-parsoid='{"pi":[[{"k":"1","named":true}]]}' 
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;ref
 class=\"hi\n|ho\">ha&lt;/ref>"}},"i":0}}]}'><a href="./Main_Page#cite_note-1" 
style="counter-reset: mw-Ref 1;"><span 
class="mw-reflink-text">[1]</span></a></span></p>
+
+<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" 
data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" 
id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span 
class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" 
class="mw-reference-text" data-parsoid="{}">ha</span></li></ol>
+!! end
+
 ## We don't support roundtripping of these attributes in Parsoid.
 ## Selective serialization takes care of preventing dirty diffs.
 ## But, on edits, we dirty-diff the invalid attribute text.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I85fd4d1273aff632abf3cf54fc4ba8293cae5f71
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <abrea...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to