From 637d4a2087b9e93ccd47d689411887b6c40c3992 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 18 Jul 2021 13:43:11 -0400 Subject: Pronunciation template helper (#1840) * Rename field * Set up pronunication components * Fix documentation * Rename function * Update test dependencies * Fix constructor * Log errors * Add pronunciation helper * Add styleApplier argument to _getHtml/_normalizeHtml * Use getAttribute for 'class' to support namespaced elements (e.g. svg) * Update format name * Add optional tag * Update docs --- docs/templates.md | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/templates.md b/docs/templates.md index 8ee3bb0c..f1777fde 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -3,7 +3,7 @@ ## Helpers Yomichan supports several custom Handlebars helpers for rendering templates. -The source code for these templates can be found [here](../ext/js/templates/sandbox/template-renderer.js). +The source code for these templates can be found [here](../ext/js/templates/sandbox/anki-template-renderer.js). ### `dumpObject` @@ -689,7 +689,7 @@ These functions are used together in order to request media and other types of o The type of media to check for. * _`args`_
Additional arguments for the media. The arguments depend on the media type. - * _`escape`_
+ * _`escape`_ _(optional)_
Whether or not the resulting text should be HTML-escaped. If omitted, defaults to `true`. **Available media types and arguments** @@ -742,6 +742,39 @@ These functions are used together in order to request media and other types of o +### `pronunciation` + +Converts pronunciation information into a formatted HTML content string. The display layout is the +same as the system used for generating popup and search page dictionary entries. + +
+ Syntax: + + {{#pronunciation format=string reading=string downstepPosition=integer [nasalPositions=array] [devoicePositions=array]}}{{/pronunciation}}
+ + * _`format`_
+ The format of the HTML to generate. This can be any of the following values: + * `'text'` + * `'graph'` + * `'position'` + * _`reading`_
+ The kana reading of the term. + * _`downstepPosition`_
+ The mora position of the downstep in the reading. + * _`nasalPositions`_ _(optional)_
+ An array of indices of mora that have a nasal pronunciation. + * _`devoicePositions`_ _(optional)_
+ An array of indices of mora that are devoiced. +
+
+ Example: + + ```handlebars + {{~#pronunciation format='text' reading='よむ' downstepPosition=1~}}{{~/pronunciation~}} + ``` +
+ + ## Legacy Helpers Yomichan has historically used Handlebars templates to generate the HTML used on the search page and results popup. -- cgit v1.2.3