From 02180c678a5f3cbd6e166e1cc953fee7494223e5 Mon Sep 17 00:00:00 2001 From: kuuuube Date: Fri, 23 Feb 2024 10:34:42 -0500 Subject: [PATCH] Remove redundant escaping --- .../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 ad2b0042d1..48270cf1f2 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 ); } @@ -675,12 +664,12 @@ export class AnkiTemplateRenderer { _formatGlossary(args, _context, options) { const [dictionary, content] = /** @type {[dictionary: string, content: import('dictionary-data').TermGlossaryContent]} */ (args); 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 ''; }