diff options
| author | Kuuuube <61125188+Kuuuube@users.noreply.github.com> | 2024-02-27 07:16:46 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-27 12:16:46 +0000 | 
| commit | e74fadc5a411e907da088729ea13e23e6f5aa58d (patch) | |
| tree | bcf0f16a7a61db2606c0a0688356e431c2d8d2f8 | |
| parent | 0792954e345925b3e3b2ebb733367e138375978e (diff) | |
Remove redundant escaping (#722)
| -rw-r--r-- | ext/js/templates/sandbox/anki-template-renderer.js | 23 | 
1 files 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 @@ -142,14 +142,6 @@ export class AnkiTemplateRenderer {       * @param {string} text       * @returns {string}       */ -    _escape(text) { -        return Handlebars.Utils.escapeExpression(text); -    } - -    /** -     * @param {string} text -     * @returns {string} -     */      _safeString(text) {          return new Handlebars.SafeString(text);      } @@ -158,8 +150,7 @@ export class AnkiTemplateRenderer {      /** @type {import('template-renderer').HelperFunction<string>} */      _dumpObject(object) { -        const dump = JSON.stringify(object, null, 4); -        return this._escape(dump); +        return JSON.stringify(object, null, 4);      }      /** @type {import('template-renderer').HelperFunction<string>} */ @@ -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 ? -                `<ruby>${safeText}<rt>${safeReading}</rt></ruby>` : -                safeText +                reading2.length > 0 ? +                `<ruby>${text}<rt>${reading2}</rt></ruby>` : +                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 '';      } |