Fix mustache template rendering when TOC is rerendered after an edit

Bug: T326682
Change-Id: I7e8f5572a33c4440aed5e6e525a48d8abe4a2afb
(cherry picked from commit 5195949674)
This commit is contained in:
bwang 2023-01-10 19:54:03 -06:00 committed by Jdrewniak
parent 044397180c
commit cc9cbd96e9
2 changed files with 16 additions and 2 deletions

View file

@ -5,6 +5,8 @@
*/
const templateBody = require( /** @type {string} */ ( './templates/TableOfContents.mustache' ) );
const templateTocLine = require( /** @type {string} */ ( './templates/TableOfContents__line.mustache' ) );
const templatePinnableElementOpen = require( /** @type {string} */ ( './templates/PinnableElement/Open.mustache' ) );
const templatePinnableElementClose = require( /** @type {string} */ ( './templates/PinnableElement/Close.mustache' ) );
/**
* TableOfContents Config object for filling mustache templates
*/
@ -462,12 +464,14 @@ module.exports = function tableOfContents( props ) {
// @ts-ignore
const mustacheCompiler = mw.template.getCompiler( 'mustache' );
const compiledTemplateBody = mustacheCompiler.compile( templateBody );
const compiledTemplateTocLine = mustacheCompiler.compile( templateTocLine );
// Identifier 'TableOfContents__line' is not in camel case
// (template name is 'TableOfContents__line')
const partials = {
TableOfContents__line: compiledTemplateTocLine // eslint-disable-line camelcase
// eslint-disable-next-line camelcase
TableOfContents__line: mustacheCompiler.compile( templateTocLine ),
'PinnableElement/Open': mustacheCompiler.compile( templatePinnableElementOpen ),
'PinnableElement/Close': mustacheCompiler.compile( templatePinnableElementClose )
};
return compiledTemplateBody.render( data, partials ).html();

View file

@ -365,6 +365,16 @@
"VectorTableOfContentsBeginning"
]
},
{
"name": "resources/skins.vector.es6/templates/PinnableElement/Open.mustache",
"file": "includes/templates/PinnableElement/Open.mustache",
"type": "text"
},
{
"name": "resources/skins.vector.es6/templates/PinnableElement/Close.mustache",
"file": "includes/templates/PinnableElement/Close.mustache",
"type": "text"
},
{
"name": "resources/skins.vector.es6/templates/TableOfContents.mustache",
"file": "includes/templates/TableOfContents.mustache",