aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-24 21:54:58 -0500
committerGitHub <noreply@github.com>2021-02-24 21:54:58 -0500
commitae92e0b3781e27d54cbac2570ba2a1b8a6b11999 (patch)
treeb7d7a7171a6cbc25d5f1fc4b4996024c4f73033e /ext/js/data/anki-note-builder.js
parent0a76de1b44443cc668882125d73d83d5f7ba8a63 (diff)
AnkiUtil (#1439)
* Add AnkiUtil * Update AnkiConnect to use AnkiUtil * Use AnkiUtil in AnkiNoteBuilder * Replace containsAnyMarker with AnkiUtil.stringContainsAnyFieldMarker * Add AnkiUtil.getFieldMarkers * Add fieldsObjectContainsMarker to AnkiUtil * Remove unused global * Remove unused parameter: enabled * Add cloneFieldMarkerPattern
Diffstat (limited to 'ext/js/data/anki-note-builder.js')
-rw-r--r--ext/js/data/anki-note-builder.js30
1 files changed, 5 insertions, 25 deletions
diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js
index e1399f66..f12846b1 100644
--- a/ext/js/data/anki-note-builder.js
+++ b/ext/js/data/anki-note-builder.js
@@ -16,13 +16,14 @@
*/
/* global
+ * AnkiUtil
* TemplateRendererProxy
*/
class AnkiNoteBuilder {
- constructor(enabled) {
- this._markerPattern = /\{([\w-]+)\}/g;
- this._templateRenderer = enabled ? new TemplateRendererProxy() : null;
+ constructor() {
+ this._markerPattern = AnkiUtil.cloneFieldMarkerPattern(true);
+ this._templateRenderer = new TemplateRendererProxy();
}
async createNote({
@@ -46,7 +47,7 @@ class AnkiNoteBuilder {
let duplicateScopeCheckChildren = false;
if (duplicateScope === 'deck-root') {
duplicateScope = 'deck';
- duplicateScopeDeckName = this.getRootDeckName(deckName);
+ duplicateScopeDeckName = AnkiUtil.getRootDeckName(deckName);
duplicateScopeCheckChildren = true;
}
@@ -89,27 +90,6 @@ class AnkiNoteBuilder {
};
}
- containsMarker(fields, marker) {
- marker = `{${marker}}`;
- for (const [, fieldValue] of fields) {
- if (fieldValue.includes(marker)) {
- return true;
- }
- }
- return false;
- }
-
- containsAnyMarker(field) {
- const result = this._markerPattern.test(field);
- this._markerPattern.lastIndex = 0;
- return result;
- }
-
- getRootDeckName(deckName) {
- const index = deckName.indexOf('::');
- return index >= 0 ? deckName.substring(0, index) : deckName;
- }
-
// Private
async _formatField(field, data, templates, errors=null) {