aboutsummaryrefslogtreecommitdiff
path: root/ext/js/templates/template-renderer-media-provider.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-09 17:48:27 -0400
committerGitHub <noreply@github.com>2021-07-09 17:48:27 -0400
commit8c68fa4d9435b562ffe23df92a2b7b620a0ed78e (patch)
tree8c622fe11063b3f9694033f10e47b2ac05badccc /ext/js/templates/template-renderer-media-provider.js
parent0d167095479822adf1ed8918e3d1a349b3a53377 (diff)
Anki text furigana parsing and {sentence-furigana} marker (#1814)
* Add support for textFurigana media * Add readingMode parameter * Implement readingMode * Add {sentence-furigana} marker * Fallback to sentence if furigana isn't available * Update test data
Diffstat (limited to 'ext/js/templates/template-renderer-media-provider.js')
-rw-r--r--ext/js/templates/template-renderer-media-provider.js34
1 files changed, 19 insertions, 15 deletions
diff --git a/ext/js/templates/template-renderer-media-provider.js b/ext/js/templates/template-renderer-media-provider.js
index 4fd40c67..604b5331 100644
--- a/ext/js/templates/template-renderer-media-provider.js
+++ b/ext/js/templates/template-renderer-media-provider.js
@@ -54,21 +54,7 @@ class TemplateRendererMediaProvider {
}
_getFormattedValue(data, format) {
- switch (format) {
- case 'fileName':
- {
- const {fileName} = data;
- if (typeof fileName === 'string') { return fileName; }
- }
- break;
- case 'text':
- {
- const {text} = data;
- if (typeof text === 'string') { return text; }
- }
- break;
- }
- return null;
+ return Object.prototype.hasOwnProperty.call(data, format) ? data[format] : null;
}
_getMediaData(media, args, namedArgs) {
@@ -79,6 +65,7 @@ class TemplateRendererMediaProvider {
case 'clipboardImage': return this._getSimpleMediaData(media, 'clipboardImage');
case 'clipboardText': return this._getSimpleMediaData(media, 'clipboardText');
case 'selectionText': return this._getSimpleMediaData(media, 'selectionText');
+ case 'textFurigana': return this._getTextFurigana(media, args[1], namedArgs);
case 'dictionaryMedia': return this._getDictionaryMedia(media, args[1], namedArgs);
default: return null;
}
@@ -114,4 +101,21 @@ class TemplateRendererMediaProvider {
});
return null;
}
+
+ _getTextFurigana(media, text, namedArgs) {
+ const {readingMode=null} = namedArgs;
+ const {textFurigana} = media;
+ if (Array.isArray(textFurigana)) {
+ for (const entry of textFurigana) {
+ if (entry.text !== text || entry.readingMode !== readingMode) { continue; }
+ return entry.details;
+ }
+ }
+ this._addRequirement({
+ type: 'textFurigana',
+ text,
+ readingMode
+ });
+ return null;
+ }
}