Templates
Helpers
Rikaitan supports several custom Handlebars helpers for rendering templates.
The source code for these templates can be found here.
dumpObject
Converts an object to a pretty-printed JSON string.
This function can be helpful for debugging values when creating templates.
Syntax:
- _`object`_
The object to convert.
Example:
```handlebars
```
Output:
```html
{
"key": "value"
}
```
Preview:
```html
{
"key": "value"
}
```
furigana
Converts a definition or expression/reading pair to its furigana representation.
Syntax:
- _`definition`_
The definition to convert.
- _`expression`_
The expression to convert.
- _`reading`_
The reading to convert.
Example:
```handlebars
```
Output:
```html
θͺγ
```
Preview
θͺγ
furiganaPlain
Converts a definition or expression/reading pair to its simplified furigana representation.
Syntax:
- _`definition`_
The definition to convert.
- _`expression`_
The expression to convert.
- _`reading`_
The reading to convert.
Example:
```handlebars
```
Output:
```html
θͺ[γ]γ
```
multiLine
Replaces newline characters with a forced HTML line break <br>.
Syntax:
text with multiple lines
Example:
```handlebars
some
multiline
text
```
Output:
```html
some
multiline
text
```
Preview:
some
multiline
text
regexReplace
Uses a regular expression to replace a pattern with the specified text.
Syntax:
text-to-modify
- _`regex`_
The raw string used to create the regular expression. This value is passed to the [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) constructor.
- _`replacement`_
The text used to replace pattern matches. This supports the standard [special capture group replacements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter) as supported by the web browser.
- _`flags`_ _(optional)_
Optional flags to pass to the [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) constructor.
- _`text-to-modify`_
The text that the regular expression is applied to.
If multiple arguments are present, they are all concatenated.
Example:
```handlebars
Here is (some) (text) (in) (parentheses)
```
Output:
```html
Here is some text in parentheses
```
regexMatch
Uses a regular expression to return only the content that matches the pattern.
Syntax:
text-to-modify
- _`regex`_
The raw string used to create the regular expression. This value is passed to the [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) constructor.
- _`flags`_ _(optional)_
Optional flags to pass to the [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) constructor.
- _`text-to-modify`_
The text that the regular expression is applied to.
If multiple arguments are present, they are all concatenated.
Example:
```handlebars
Here is (some) (text) (in) (parentheses)
```
Output:
```html
(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:
- _`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:
```handlebars
```
Output:
```html
v5m, vt, JMdict (English)
```
#eachUpTo
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:
(modification)(else-modification)
- _`iterable`_
The object that should be looped over. A JavaScript [`for...of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...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:
```handlebars
}
Empty
```
Output:
```html
someArray[0]
someArray[1]
someArray[2]
someArray[3]
someArray[4]
```
Preview:
someArray[0]
someArray[1]
someArray[2]
someArray[3]
someArray[4]
spread
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:
- _`iterableN`_
A variable amount of iterable objects to combine into a single array.
Example:
```handlebars
}
```
Output:
```html
array1[0]
array1[1]
array2[0]
array2[1]
```
Preview:
array1[0]
array1[1]
array2[0]
array2[1]
op
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:
- _`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:
```handlebars
Values are equal
```
Output:
```html
Values are equal
-32
a
```
Preview:
Values are equal
-32
a
get
Gets a value from the custom state stack.
Syntax:
- _`name`_
The name of the variable to get.
Example:
```handlebars
```
Output:
```html
This is the value of some-text!
```
set
Assigns a value to the custom state stack.
Syntax:
value
- _`name`_
The name of the variable to assign.
- _`value`_
The value of the variable.
Example:
```handlebars
This is the value of some-text!
```
Output:
```html
```
#scope
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:
content
- _`name`_
The name of the variable to assign.
- _`value`_
The value of the variable.
Example:
```handlebars
,
,
,
```
Output:
```html
32,32,64,32
```
property
Repeatedly gets a property of an object.
Syntax:
- _`object`_
The initial object to use.
- _`propertyN`_
A chain of property names to get on the object.
Example:
```handlebars
```
Output:
```html
function toString() { [native code] }
```
noop
No-op. Returns the inner contents of the template.
Syntax:
content
Example:
```handlebars
Unchanged content
```
Output:
```html
Unchanged content
```
isMoraPitchHigh
Returns whether or not a mora will have a high pitch, given the index of the mora and the position of the downstep.
Syntax:
Example:
```handlebars
High pitchLow pitch
```
Output:
```html
High pitch
```
getKanaMorae
Returns an array of the mora for a kana string.
Syntax:
Example:
```handlebars
}
```
Output:
```html
γ
γΏ
γ
γ
```
Preview:
γ
γΏ
γ
γ
typeof
Returns the type of a value. #typeof in the block form will always return 'string'.
Syntax:
value
- _`value`_
The value to check.
Example:
```handlebars
γγγγγ
```
Output:
```html
string
number
string
```
join
Joins the arguments to a single string with a separator, flattening any arguments that are arrays.
Syntax:
- _`separator`_
The separator string to use between values.
- _`valueN`_
An individual value to join into the resulting string
Example:
```handlebars
```
Output:
```html
rikaitan_32_value
```
concat
Joins the arguments to a single string, without flattening arguments that are arrays.
Syntax:
- _`valueN`_
A value to join into the resulting string
Example:
```handlebars
```
Output:
```html
rikaitan_32_value
```
pitchCategories
Returns an array representing the different pitch categories for a specific term.
Syntax:
- _`@root`_
The argument passed should always be the root data object.
Example:
```handlebars
[, ]
```
Output:
```html
[heiban, kifuku]
```
Formats a glossary entry to a HTML content string. This helper handles image and
structured-content generation.
Syntax:
- _`dictionary`_
The dictionary that the glossary entry belongs to.
- _`definitionEntry`_
The definition entry object in raw form.
Example:
```handlebars
```
Output:
```html
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:
- _`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 to `true`.
**Available media types and arguments**
- "audio"
- "screenshot"
- "clipboardImage"
- "clipboardText"
- "popupSelectionText"
- "textFurigana" japaneseText readingMode="default|hiragana|katakana"
- "dictionaryMedia" fileName dictionary="Dictionary Name"
Examples:
```handlebars
The audio file name is:
The screenshot file name is:
The clipboard image file name is:
The clipboard text is:
The popup selection text is:
This is an example of text with generated furigana:
The remapped file name for image.png is:
```
Output:
```html
The audio file name is: rikaitan_audio_γ«γ»γγ_ζ₯ζ¬θͺ.mp3
The screenshot file name is: rikaitan_browser_screenshot_γ«γ»γγ_ζ₯ζ¬θͺ.png
The clipboard image file name is: rikaitan_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: ζ₯ζ¬θͺ
The remapped file name for image.png is: rikaitan_dictionary_media_1_γ«γ»γγ_ζ₯ζ¬θͺ.png
```
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:
- _`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
```
hiragana
Converts katakana text to hiragana.
Syntax:
value
- _`value`_
The text to convert.
- _`keepProlongedSoundMarks`_ _(optional)_
Whether or not the `γΌ` character should be kept or converted to a vowel character.
Defaults to `false` if not specified.
Example:
```handlebars
γγγγγ γͺγ«γ€γγ γͺγ«γ€γΏγ³
γγΌγε
γγΌγε
```
Output:
```html
γγγγγ γγγγγ γγγγγ
γγγγγ γγγγγ γγγγγ
γγγΎε
γγΌγΎε
```
katakana
Converts hiragana text to katakana.
Syntax:
text
- _`text`_
The text to convert.
Example:
```handlebars
γγγγγ γͺγ«γ€γγ γͺγ«γ€γΏγ³
```
Output:
```html
γͺγ«γ€γΏγ³ γͺγ«γ€γΏγ³ γͺγ«γ€γΏγ³
γͺγ«γ€γΏγ³ γͺγ«γ€γΏγ³ γͺγ«γ€γΏγ³
```