Page MenuHomePhabricator

Extlink url should be terminated by extension tag
Open, LowPublic

Description

The template רמב"י (pronounced "rambi") in the Hebrew Wikipedia is rendered correctly when reading a page. However, when a page that transcludes is edited in the Visual Editor, shows a URL with its wiki syntax.

This can probably be somehow fixed in the template, but if the rendering is so different between the rendered page and the Visual Editor, I suspect that there may be a bug in VE.

To see an example, go to the page https://he.wikipedia.org/wiki/%D7%9E%D7%A9%D7%AA%D7%9E%D7%A9:Amire80/rambi and try editing it using VE.

The revision of the template with which the problems occurs is https://he.wikipedia.org/w/index.php?title=%D7%AA%D7%91%D7%A0%D7%99%D7%AA:%D7%A8%D7%9E%D7%91%22%D7%99&oldid=24140419

Event Timeline

A reduced test case is,

[http://testing.com<nowiki> </nowiki>123]

but more generally needs to account for all extension tags. Could fix this in the grammar to not soak up the extension tags in the directives of extlink_preprocessor_text but would still need to account for templates returning extension tags in the LinkHandler, something like what follows.


diff --git a/lib/wt2html/tt/LinkHandler.js b/lib/wt2html/tt/LinkHandler.js
index f08c399b..3accbb5c 100644
--- a/lib/wt2html/tt/LinkHandler.js
+++ b/lib/wt2html/tt/LinkHandler.js
@@ -2076,13 +2076,24 @@ class ExternalLinkHandler extends TokenHandler {
        onExtLink(token, manager, cb) {
                let newAttrs, aStart;
                const env = this.manager.env;
-               const origHref = token.getAttribute('href');
+               let content = token.getAttribute('mw:content');
+               let origHref = token.getAttribute('href');
+               let addNormalizedAttribute = true;
+               if (Array.isArray(origHref)) {
+                       addNormalizedAttribute = !origHref.some((t, i) => {
+                               if (t.constructor === TagTk && t.getAttribute('typeof') === 'mw:Nowiki') {
+                                       content = origHref.slice(i).concat(content);
+                                       origHref = origHref.slice(0, i);
+                                       return true;
+                               }
+                               return false;
+                       });
+               }
                const hasExpandedAttrs = /mw:ExpandedAttrs/.test(token.getAttribute('typeof'));
                const href = Util.tokensToString(origHref);
                const hrefWithEntities = Util.tokensToString(origHref, false, {
                        includeEntities: true,
                });
-               let content = token.getAttribute('mw:content');
                const dataAttribs = Util.clone(token.dataAttribs);
                let rdfaType = token.getAttribute('typeof');
                const magLinkRe = /(?:^|\s)(mw:(?:Ext|Wiki)Link\/(?:ISBN|RFC|PMID))(?=$|\s)/;
@@ -2145,7 +2156,7 @@ class ExternalLinkHandler extends TokenHandler {
                        newAttrs = WikiLinkHandler.buildLinkAttrs(token.attribs, false, null, newAttrs).attribs;
                        aStart = new TagTk('a', newAttrs, dataAttribs);
 
-                       if (!this.options.inTemplate) {
+                       if (addNormalizedAttribute && !this.options.inTemplate) {
                                // If we are from a top-level page, add normalized attr info for
                                // accurate roundtripping of original content.
                                //
Arlolra triaged this task as Medium priority.Oct 22 2018, 11:50 PM
Arlolra renamed this task from The Hebrew Wikipedia "rambi" template is rendered correctly, but is displayed incorrectly when edited in Visual Editor to Extlink url should be terminated by extension tag.Oct 22 2018, 11:52 PM
Arlolra moved this task from Needs Triage to Link syntax (links & media) on the Parsoid board.
ssastry lowered the priority of this task from Medium to Low.Feb 28 2020, 5:24 PM
ssastry moved this task from Link syntax (links & media) to Bugs & Crashers on the Parsoid board.