Omit the sound tag if it's empty (#525)

This commit is contained in:
toasted-nutbread 2020-05-09 12:29:41 -04:00 committed by GitHub
parent 9900291b07
commit bdbe680f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -14,9 +14,11 @@
{{~/if~}} {{~/if~}}
{{/inline}} {{/inline}}
{{#*inline "audio"~}} {{#*inline "audio"}}
{{~#if definition.audioFileName~}}
[sound:{{definition.audioFileName}}] [sound:{{definition.audioFileName}}]
{{~/inline}} {{~/if~}}
{{/inline}}
{{#*inline "character"}} {{#*inline "character"}}
{{~definition.character~}} {{~definition.character~}}

View File

@ -115,7 +115,7 @@ const profileOptionsVersionUpdates = [
let fieldTemplates = options.anki.fieldTemplates; let fieldTemplates = options.anki.fieldTemplates;
if (typeof fieldTemplates !== 'string') { return; } if (typeof fieldTemplates !== 'string') { return; }
const replacement = '{{#*inline "audio"~}}\n [sound:{{definition.audioFileName}}]\n{{~/inline}}'; const replacement = '{{#*inline "audio"}}\n {{~#if definition.audioFileName~}}\n [sound:{{definition.audioFileName}}]\n {{~/if~}}\n{{/inline}}';
let replaced = false; let replaced = false;
fieldTemplates = fieldTemplates.replace(/\{\{#\*inline "audio"\}\}\{\{\/inline\}\}/g, () => { fieldTemplates = fieldTemplates.replace(/\{\{#\*inline "audio"\}\}\{\{\/inline\}\}/g, () => {
replaced = true; replaced = true;