Yomitan supports several custom Handlebars helpers for rendering templates. The source code for these templates can be found here.
Converts an object to a pretty-printed JSON string. This function can be helpful for debugging values when creating templates.
Syntax:
{{dumpObject object}}
object
The object to convert.
Example:
Output:
<pre>{
"key": "value"
}</pre>
Preview:
{
"key": "value"
}
Converts a definition or expression/reading pair to its furigana representation.
Syntax:
{{furigana definition}}
{{furigana expression reading}}
definition
The definition to convert.expression
The expression to convert.reading
The reading to convert.
Example:
Output:
<ruby>読<rt>よ</rt></ruby>む
Preview
読む
Converts a definition or expression/reading pair to its simplified furigana representation.
Syntax:
{{furiganaPlain definition}}
{{furiganaPlain expression reading}}
definition
The definition to convert.expression
The expression to convert.reading
The reading to convert.
Example:
Output:
読[よ]む
Replaces newline characters with a forced HTML line break <br>
.
Syntax:
{{#multiLine}}text with multiple lines{{/multiLine}}
Example:
Output:
some<br>multiline<br>text
Preview:
some
multiline
text
Uses a regular expression to replace a pattern with the specified text.
Syntax:
{{#regexReplace regex replacement [flags]}}text-to-modify{{/regexReplace}}
{{regexReplace regex replacement [flags] [text-to-modify]...}}
regex
The raw string used to create the regular expression. This value is passed to theRegExp
constructor.replacement
The text used to replace pattern matches. This supports the standard special capture group replacements as supported by the web browser.flags
(optional)
Optional flags to pass to theRegExp
constructor.text-to-modify
The text that the regular expression is applied to. If multiple arguments are present, they are all concatenated.
Example:
Output:
Here is some text in parentheses
Uses a regular expression to return only the content that matches the pattern.
Syntax:
{{#regexMatch regex [flags]}}text-to-modify{{/regexMatch}}
{{regexMatch regex [flags] [text-to-modify]...}}
regex
The raw string used to create the regular expression. This value is passed to theRegExp
constructor.flags
(optional)
Optional flags to pass to theRegExp
constructor.text-to-modify
The text that the regular expression is applied to. If multiple arguments are present, they are all concatenated.
Example:
Output:
(some)(text)(in)(parentheses)
Creates a set of all unique tags for the definition and returns a text representation of the tags separated by commas.
Syntax:
{{mergeTags definition isGroupMode isMergeMode}}
definition
The root definition object.isGroupMode
(optional)
Whether or not the display mode is the 'group' mode.isMergeMode
Whether or not the display mode is the 'merge' mode.
Example:
Output:
v5m, vt, JMdict (English)
Similar to the built-in #each
function, but iterates up to a maximum count.
If the iterable is falsy or empty, the else
condition will be used.
Syntax:
{{#eachUpTo iterable maxCount}}(modification){{else}}(else-modification){{/eachUpTo}}
iterable
The object that should be looped over. A JavaScriptfor...of
loop is used, so the object only needs to be iterable.maxCount
(optional)
The maximum number of entries to loop over.modification
The template used to modify the value. The context is changed to the current item of iteration.else-modification
The template used in case the iterable is falsy or empty. The context is unchanged.
Example:
Output:
someArray[0]<br>someArray[1]<br>someArray[2]<br>someArray[3]<br>someArray[4]<br>
Preview:
someArray[0]
someArray[1]
someArray[2]
someArray[3]
someArray[4]
Uses the JavaScript spread operator to convert one or more iterables into a single array.
This allows it to be used similar to an Array.concat
operation.
Syntax:
{{spread iterable1 iterable2 ... iterableN}}
iterableN
A variable amount of iterable objects to combine into a single array.
Example:
Output:
array1[0]<br>array1[1]<br>array2[0]<br>array2[1]<br>
Preview:
array1[0]
array1[1]
array2[0]
array2[1]
Performs a simple operation on one, two, or three arguments. The operations available are:
- Unary operators:
+
,-
,~
,!
- Binary operators:
+
,-
,/
,*
,%
,**
,==
,!=
,===
,!==
,<
,<=
,>
,>=
,<<
,>>
,>>>
,&
,|
,^
,&&
,||
- Ternary operators:
?:
If an unknown operator is specified, the undefined
value is returned.
Syntax:
{{op operator operand1 [operand2] [operand3]}}
operator
One of the unary, binary, or ternary operators.operand1
The first operand of the operation.operand2
(Optional)
The second operand of the operation.operand3
(Optional)
The third operand of the operation.
Example:
Output:
Values are equal<br>-32<br>a
Preview:
Values are equal
-32
a
Gets a value from the custom state stack.
Syntax:
{{get name}}
name
The name of the variable to get.
Example:
Output:
This is the value of some-text!
Assigns a value to the custom state stack.
Syntax:
{{#set name}}value{{/get}}
{{set name value}}
name
The name of the variable to assign.value
The value of the variable.
Example:
Output:
Pushes a new variable scope to the custom state stack. Variable assignments are applied to the most recent scope, and variable lookups will start from the most recent scope and work backwards until a value is found.
Syntax:
{{#scope}}content{{/scope}}
name
The name of the variable to assign.value
The value of the variable.
Example:
Output:
32,32,64,32
Repeatedly gets a property of an object.
Syntax:
{{property object property1 property2 ... propertyN}}
object
The initial object to use.propertyN
A chain of property names to get on the object.
Example:
Output:
function toString() { [native code] }
No-op. Returns the inner contents of the template.
Syntax:
{{#noop}}content{{/noop}}
Example:
Output:
Unchanged content
Returns whether or not a mora will have a high pitch, given the index of the mora and the position of the downstep.
Syntax:
{{isMoraPitchHigh index position}}
Example:
Output:
High pitch
Returns an array of the mora for a kana string.
Syntax:
{{getKanaMorae kana-string}}
Example:
Output:
よ<br>み<br>た<br>ん<br>
Preview:
よ
み
た
ん
Returns the type of a value. #typeof
in the block form will always return 'string'
.
Syntax:
{{typeof value}}
{{#typeof}}value{{/typeof}}
value
The value to check.
Example:
Output:
string
number
string
Joins the arguments to a single string with a separator, flattening any arguments that are arrays.
Syntax:
{{join separator value1 value2 valueN...}}
separator
The separator string to use between values.valueN
An individual value to join into the resulting string
Example:
Output:
yomitan_32_value
Joins the arguments to a single string, without flattening arguments that are arrays.
Syntax:
{{concat value1 value1 valueN...}}
valueN
A value to join into the resulting string
Example:
Output:
yomitan_32_value
Returns an array representing the different pitch categories for a specific term.
Syntax:
{{pitchCategories @root}}
@root
The argument passed should always be the root data object.
Example:
Output:
[heiban, kifuku]
Formats a glossary entry to a HTML content string. This helper handles image and structured-content generation.
Syntax:
{{formatGlossary dictionary definitionEntry}}
dictionary
The dictionary that the glossary entry belongs to.definitionEntry
The definition entry object in raw form.
Example:
Output:
Here is the content of a gloss, which may include formatted HTML.
Checks to see if a certain type of media is available for a card and injects the relevant content. These functions are used together in order to request media and other types of optional asynchronous content.
Syntax:
{{hasMedia type args...}}
{{getMedia type args... [escape=true|false]}}
type
The type of media to check for.args
Additional arguments for the media. The arguments depend on the media type.escape
(optional)
Whether or not the resulting text should be HTML-escaped. If omitted, defaults totrue
.
Available media types and arguments
"audio"
"screenshot"
"clipboardImage"
"clipboardText"
"popupSelectionText"
"textFurigana" japaneseText readingMode="default|hiragana|katakana"
"dictionaryMedia" fileName dictionary="Dictionary Name"
Examples:
Output:
The audio file name is: yomitan_audio_にほんご_日本語.mp3
The screenshot file name is: yomitan_browser_screenshot_にほんご_日本語.png
The clipboard image file name is: yomitan_clipboard_image_にほんご_日本語.png
The clipboard text is: This is the clipboard text
The selection text is: This is the selection text
The selection text is: This is the selection text
This is an example of text with generated furigana: <ruby>日本語<rt>にほんご</rt></ruby>
The remapped file name for image.png is: yomitan_dictionary_media_1_にほんご_日本語.png
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]}}
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:
Converts katakana text to hiragana.
Syntax:
{{hiragana value [keepProlongedSoundMarks=true|false]}}
{{#hiragana [keepProlongedSoundMarks=true|false]}}value{{/hiragana}}
value
The text to convert.keepProlongedSoundMarks
(optional)
Whether or not theー
character should be kept or converted to a vowel character. Defaults tofalse
if not specified.
Example:
Output:
よみたん よみたん よみたん
よみたん よみたん よみたん
ろうま字
ろーま字
Converts hiragana text to katakana.
Syntax:
{{katakana text}}
{{#katakana}}text{{/katakana}}
text
The text to convert.
Example:
Output:
ヨミタン ヨミタン ヨミタン
ヨミタン ヨミタン ヨミタン