Skip to content

Commit

Permalink
Remove redundant escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Feb 23, 2024
1 parent 9b5de0d commit 02180c6
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions ext/js/templates/sandbox/anki-template-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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>} */
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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 '';
}
Expand Down

0 comments on commit 02180c6

Please sign in to comment.