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
This commit is contained in:
C. Scott Ananian 2019-04-19 15:38:27 -04:00 committed by jenkins-bot
parent c790d125de
commit b84b71af22
4 changed files with 25 additions and 17 deletions

View file

@ -29,14 +29,16 @@ class Ref {
// in-memory DOM which is simply a tree data structure, we can // in-memory DOM which is simply a tree data structure, we can
// nest flow content in a <sup> tag. // nest flow content in a <sup> tag.
wrapperTag: 'sup', wrapperTag: 'sup',
inTemplate: state.parseContext.inTemplate, pipelineOpts: {
extTag: 'ref', extTag: 'ref',
extTagOpts: { extTagOpts: {
allowNestedRef: !!allowNestedRef, 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,
}); });
} }

View file

@ -26,8 +26,10 @@ class References {
static toDOM(state, content, args) { static toDOM(state, content, args) {
return ParsoidExtApi.parseTokenContentsToDOM(state, args, '', content, { return ParsoidExtApi.parseTokenContentsToDOM(state, args, '', content, {
wrapperTag: 'div', wrapperTag: 'div',
extTag: 'references', pipelineOpts: {
inTemplate: state.parseContext.inTemplate, extTag: 'references',
inTemplate: state.parseContext.inTemplate,
},
}).then(function(doc) { }).then(function(doc) {
var refsOpts = Object.assign({ var refsOpts = Object.assign({
group: null, group: null,

View file

@ -48,12 +48,14 @@ class Ref implements ExtensionTag, SerialHandler {
// in-memory DOM which is simply a tree data structure, we can // in-memory DOM which is simply a tree data structure, we can
// nest flow content in a <sup> tag. // nest flow content in a <sup> tag.
'wrapperTag' => 'sup', 'wrapperTag' => 'sup',
'inTemplate' => $extApi->parseContext['inTemplate'] ?? null, 'pipelineOpts' => [
'extTag' => 'ref', 'extTag' => 'ref',
'extTagOpts' => [ 'allowNestedRef' => $allowNestedRef ], 'extTagOpts' => [ 'allowNestedRef' => $allowNestedRef ],
// FIXME: One-off PHP parser state leak. 'inTemplate' => $extApi->parseContext['inTemplate'] ?? null,
// This needs a better solution. // FIXME: One-off PHP parser state leak.
'inPHPBlock' => true, // This needs a better solution.
'inPHPBlock' => true,
],
] ]
); );
} }

View file

@ -486,8 +486,10 @@ class References implements ExtensionTag, SerialHandler {
$txt, $txt,
[ [
'wrapperTag' => 'div', 'wrapperTag' => 'div',
'extTag' => 'references', 'pipelineOpts' => [
'inTemplate' => $extApi->parseContext['inTemplate'] ?? null, 'extTag' => 'references',
'inTemplate' => $extApi->parseContext['inTemplate'] ?? null,
],
] ]
); );