From e74fadc5a411e907da088729ea13e23e6f5aa58d Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Tue, 27 Feb 2024 07:16:46 -0500 Subject: Remove redundant escaping (#722) --- ext/js/templates/sandbox/anki-template-renderer.js | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js index d2bb25d5..8fe248ac 100644 --- a/ext/js/templates/sandbox/anki-template-renderer.js +++ b/ext/js/templates/sandbox/anki-template-renderer.js @@ -138,14 +138,6 @@ export class AnkiTemplateRenderer { this._cleanupCallbacks.length = 0; } - /** - * @param {string} text - * @returns {string} - */ - _escape(text) { - return Handlebars.Utils.escapeExpression(text); - } - /** * @param {string} text * @returns {string} @@ -158,8 +150,7 @@ export class AnkiTemplateRenderer { /** @type {import('template-renderer').HelperFunction} */ _dumpObject(object) { - const dump = JSON.stringify(object, null, 4); - return this._escape(dump); + return JSON.stringify(object, null, 4); } /** @type {import('template-renderer').HelperFunction} */ @@ -169,12 +160,10 @@ export class AnkiTemplateRenderer { let result = ''; for (const {text, reading: reading2} of segments) { - const safeText = this._escape(text); - const safeReading = this._escape(reading2); result += ( - safeReading.length > 0 ? - `${safeText}${safeReading}` : - safeText + reading2.length > 0 ? + `${text}${reading2}` : + text ); } @@ -676,12 +665,12 @@ export class AnkiTemplateRenderer { const [dictionary, content] = /** @type {[dictionary: string, content: import('dictionary-data').TermGlossaryContent]} */ (args); /** @type {import('anki-templates').NoteData} */ const data = options.data.root; - if (typeof content === 'string') { return this._stringToMultiLineHtml(this._escape(content)); } + if (typeof content === 'string') { return this._stringToMultiLineHtml(content); } if (!(typeof content === 'object' && content !== null)) { return ''; } switch (content.type) { case 'image': return this._formatGlossaryImage(content, dictionary, data); case 'structured-content': return this._formatStructuredContent(content, dictionary, data); - case 'text': return this._stringToMultiLineHtml(this._escape(content.text)); + case 'text': return this._stringToMultiLineHtml(content.text); } return ''; } -- cgit v1.2.3