From b84b71af221f4d7c18471588869bbe202088123e Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Fri, 19 Apr 2019 15:38:27 -0400 Subject: [PATCH] Gallery: shift TSRs in the DOM, rather than fibbing about srcOffset Passing srcOffsets which don't actually correspond to actual regions of the source wikitext cause problems in the token offset conversion code. Instead, parse the wikitext as itself, then adjust the TSRs in the DOM tree. Since Gallery isn't ported to PHP (yet), update the automatically-generated Gallery/index.php. The newly-added ContentUtils::shiftDSR() was ported, however. Change-Id: I28f3d3398930733ae2bcf9759e49c45f93bc7190 --- lib/ext/Cite/Ref.js | 16 +++++++++------- lib/ext/Cite/References.js | 6 ++++-- src/Parsoid/Ref.php | 14 ++++++++------ src/Parsoid/References.php | 6 ++++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/ext/Cite/Ref.js b/lib/ext/Cite/Ref.js index 6c7bf4dba..e27266cf7 100644 --- a/lib/ext/Cite/Ref.js +++ b/lib/ext/Cite/Ref.js @@ -29,14 +29,16 @@ class Ref { // in-memory DOM which is simply a tree data structure, we can // nest flow content in a tag. wrapperTag: 'sup', - inTemplate: state.parseContext.inTemplate, - extTag: 'ref', - extTagOpts: { - allowNestedRef: !!allowNestedRef, + pipelineOpts: { + extTag: 'ref', + extTagOpts: { + allowNestedRef: !!allowNestedRef, + }, + inTemplate: state.parseContext.inTemplate, + // FIXME: One-off PHP parser state leak. + // This needs a better solution. + inPHPBlock: true, }, - // FIXME: One-off PHP parser state leak. - // This needs a better solution. - inPHPBlock: true, }); } diff --git a/lib/ext/Cite/References.js b/lib/ext/Cite/References.js index e7bca1cd5..d191cdb0a 100644 --- a/lib/ext/Cite/References.js +++ b/lib/ext/Cite/References.js @@ -26,8 +26,10 @@ class References { static toDOM(state, content, args) { return ParsoidExtApi.parseTokenContentsToDOM(state, args, '', content, { wrapperTag: 'div', - extTag: 'references', - inTemplate: state.parseContext.inTemplate, + pipelineOpts: { + extTag: 'references', + inTemplate: state.parseContext.inTemplate, + }, }).then(function(doc) { var refsOpts = Object.assign({ group: null, diff --git a/src/Parsoid/Ref.php b/src/Parsoid/Ref.php index c4018379c..a27682806 100644 --- a/src/Parsoid/Ref.php +++ b/src/Parsoid/Ref.php @@ -48,12 +48,14 @@ class Ref implements ExtensionTag, SerialHandler { // in-memory DOM which is simply a tree data structure, we can // nest flow content in a tag. 'wrapperTag' => 'sup', - 'inTemplate' => $extApi->parseContext['inTemplate'] ?? null, - 'extTag' => 'ref', - 'extTagOpts' => [ 'allowNestedRef' => $allowNestedRef ], - // FIXME: One-off PHP parser state leak. - // This needs a better solution. - 'inPHPBlock' => true, + 'pipelineOpts' => [ + 'extTag' => 'ref', + 'extTagOpts' => [ 'allowNestedRef' => $allowNestedRef ], + 'inTemplate' => $extApi->parseContext['inTemplate'] ?? null, + // FIXME: One-off PHP parser state leak. + // This needs a better solution. + 'inPHPBlock' => true, + ], ] ); } diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index 9816cbb24..7545d54f6 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -486,8 +486,10 @@ class References implements ExtensionTag, SerialHandler { $txt, [ 'wrapperTag' => 'div', - 'extTag' => 'references', - 'inTemplate' => $extApi->parseContext['inTemplate'] ?? null, + 'pipelineOpts' => [ + 'extTag' => 'references', + 'inTemplate' => $extApi->parseContext['inTemplate'] ?? null, + ], ] );