From 76276e78dac387df66384a10bc1179c90ebd93fe Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 17 May 2021 20:18:37 -0400 Subject: Expose search query to anki template renderer (#1686) * Expose query and fullQuery to Anki context * Add {search-query} marker * Update test data * Update tests * Wrap search query in multiLine --- ext/js/data/anki-note-data-creator.js | 4 +++- ext/js/data/options-util.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'ext/js/data') diff --git a/ext/js/data/anki-note-data-creator.js b/ext/js/data/anki-note-data-creator.js index d1bbec18..4cf62788 100644 --- a/ext/js/data/anki-note-data-creator.js +++ b/ext/js/data/anki-note-data-creator.js @@ -141,9 +141,11 @@ class AnkiNoteDataCreator { } _getPublicContext(context) { - let {documentTitle} = this._asObject(context); + let {documentTitle, query, fullQuery} = this._asObject(context); if (typeof documentTitle !== 'string') { documentTitle = ''; } return { + query, + fullQuery, document: { title: documentTitle } diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index cb58206f..00ad890d 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -461,7 +461,7 @@ class OptionsUtil { {async: false, update: this._updateVersion9.bind(this)}, {async: true, update: this._updateVersion10.bind(this)}, {async: false, update: this._updateVersion11.bind(this)}, - {async: false, update: this._updateVersion12.bind(this)} + {async: true, update: this._updateVersion12.bind(this)} ]; } @@ -813,9 +813,11 @@ class OptionsUtil { return options; } - _updateVersion12(options) { + async _updateVersion12(options) { // Version 12 changes: // Changed sentenceParsing.enableTerminationCharacters to sentenceParsing.terminationCharacterMode. + // Added {search-query} field marker. + await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v12.handlebars'); for (const profile of options.profiles) { const {sentenceParsing} = profile.options; sentenceParsing.terminationCharacterMode = sentenceParsing.enableTerminationCharacters ? 'custom' : 'newlines'; -- cgit v1.2.3