Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/96075
Change subject: WIP: Fixes to [opt-prefix{{echo|foo}}opt-suffix] parsing
......................................................................
WIP: Fixes to [opt-prefix{{echo|foo}}opt-suffix] parsing
* Wikitext like [{{echo|foo}}] has always been uneditable in VE
since {{echo|foo}} was being wrapped in a Placeholder span rather
than being represented as a transclusion.
This is an artefact of how [..] wikitext is handled. Those are
always parsed to ext-links and once internal content is fully
expanded, the ext-link token is converted to non-extlink tokens
if it is not a real ext-link.
* This patch fixes this behavior by converting fully-expanded
attribute content (since 283bfd55, expanded attributes are
expanded all the way to HTML) as DOM fragments which then get
unwrapped further down the pipeline.
FIXME: This is incomplete, hence WIP.
* No change in parser tests. We need Parsoid-only tests that
specs this behavior.
Change-Id: I45545179819bb3df60978e73638f41eac7e8c872
---
M js/lib/ext.core.LinkHandler.js
M js/lib/mediawiki.DOMUtils.js
2 files changed, 41 insertions(+), 22 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/75/96075/1
diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index a410c1a..bbfe063 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -1395,35 +1395,54 @@
} else {
// Not a link, convert href to plain text.
var tokens = ['['],
- closingTok = null,
spaces = token.getAttribute('spaces') || '';
if ((token.getAttribute("typeof") ||
"").match(/mw:ExpandedAttrs/)) {
// The token 'non-url' came from a template.
- // Introduce a span and capture the original source for
RT purposes.
+ // Extract the href's html and represent it as a
dom-fragment.
+ // FIXME: Note that this effectively creates a parsing
scope
+ // for this content which could lead to subtle diffs in
some odd/buggy
+ // wikitext use cases.
var da = token.dataAttribs,
- // targetOff covers all spaces before content
- // and we need src without those spaces.
- tsr0b = da.tsr[0] + 1,
- tsr1b = da.targetOff - spaces.length,
- span = new TagTk('span', [new KV('typeof',
'mw:Placeholder')], {
- tsr: [tsr0b, tsr1b],
- src:
env.page.src.substring(tsr0b, tsr1b)
- } );
+ dataMW =
JSON.parse(token.getAttribute('data-mw')),
+ html = dataMW.attribs[0][1].html;
- tokens.push(span);
- closingTok = new EndTagTk('span');
- }
+ // Strip leading/trailing plain-text since dom-fragment
encap/unwrap
+ // code seem to choke with leading/trailing text nodes
+ var matches = html.match(/^([^<]*)(<.*?>)([^>]*$)/),
+ prefix = matches[1],
+ html = matches[2],
+ suffix = matches[3];
- var hrefText = token.getAttribute("href");
- if (hrefText.constructor === Array) {
- tokens = tokens.concat(hrefText);
+ var toks = DU.encapsulateExpansionHTML(env, null, {
+ html: html,
+ nodes:
DU.parseHTML(html).body.childNodes
+ }, {
+ // targetOff covers all spaces
before content
+ // and we need src without
those spaces.
+ tsr: [
+ da.tsr[0] + 1 +
prefix.length,
+ da.targetOff -
spaces.length - suffix.length
+ ],
+ noAboutId: true
+ }
+ );
+
+ if (prefix) {
+ tokens.push(prefix);
+ }
+ tokens = tokens.concat(toks);
+ if (suffix) {
+ tokens.push(suffix);
+ }
} else {
- tokens.push(hrefText);
- }
-
- if (closingTok) {
- tokens.push(closingTok);
+ //
+ var hrefText = token.getAttribute("href");
+ if (hrefText.constructor === Array) {
+ tokens = tokens.concat(hrefText);
+ } else {
+ tokens.push(hrefText);
+ }
}
// FIXME: Use this attribute in regular extline
diff --git a/js/lib/mediawiki.DOMUtils.js b/js/lib/mediawiki.DOMUtils.js
index 88e030b..62fab9d 100644
--- a/js/lib/mediawiki.DOMUtils.js
+++ b/js/lib/mediawiki.DOMUtils.js
@@ -1410,7 +1410,7 @@
// Transfer the tsr.
// The first token gets the full width, the following tokens
zero width.
- var tokenTsr = token.dataAttribs ? token.dataAttribs.tsr : null;
+ var tokenTsr = opts.tsr || (token.dataAttribs ?
token.dataAttribs.tsr : null);
if (tokenTsr) {
firstWrapperToken.dataAttribs.tsr = tokenTsr;
var endTsr = [tokenTsr[1],tokenTsr[1]];
--
To view, visit https://gerrit.wikimedia.org/r/96075
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45545179819bb3df60978e73638f41eac7e8c872
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