Hiragana & katakana helpers (#1908)

* Add hiragana and katakana template helpers

* Update documentation

* Fix documentation
This commit is contained in:
toasted-nutbread 2021-08-25 21:58:51 -04:00 committed by GitHub
parent dd10dd601e
commit dfd52e1ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 3 deletions

View File

@ -539,8 +539,8 @@ Returns the type of a value.
<details> <details>
<summary>Syntax:</summary> <summary>Syntax:</summary>
<code>{{#typeof <i>value</i>}}{{/get}}</code><br> <code>{{#typeof <i>value</i>}}{{/typeof}}</code><br>
<code>{{#typeof}}<i>value</i>{{/get}}</code><br> <code>{{#typeof}}<i>value</i>{{/typeof}}</code><br>
* _`value`_ <br> * _`value`_ <br>
The value to check. The value to check.
@ -775,6 +775,64 @@ same as the system used for generating popup and search page dictionary entries.
</details> </details>
### `hiragana`
Converts katakana text to hiragana.
<details>
<summary>Syntax:</summary>
<code>{{#hiragana <i>value</i>}}{{/hiragana}}</code><br>
<code>{{#hiragana}}<i>value</i>{{/hiragana}}</code><br>
* _`value`_ <br>
The text to convert.
</details>
<details>
<summary>Example:</summary>
```handlebars
{{#hiragana "よみちゃん ヨミちゃん ヨミチャン"}}{{/hiragana}}
{{#hiragana}}よみちゃん ヨミちゃん ヨミチャン{{/hiragana}}
```
Output:
```html
よみちゃん よみちゃん よみちゃん
よみちゃん よみちゃん よみちゃん
```
</details>
### `katakana`
Converts hiragana text to katakana.
<details>
<summary>Syntax:</summary>
<code>{{#katakana <i>text</i>}}{{/katakana}}</code><br>
<code>{{#katakana}}<i>text</i>{{/katakana}}</code><br>
* _`text`_ <br>
The text to convert.
</details>
<details>
<summary>Example:</summary>
```handlebars
{{#hiragana "よみちゃん ヨミちゃん ヨミチャン"}}{{/hiragana}}
{{#hiragana}}よみちゃん ヨミちゃん ヨミチャン{{/hiragana}}
```
Output:
```html
ヨミチャン ヨミチャン ヨミチャン
ヨミチャン ヨミチャン ヨミチャン
```
</details>
## Legacy Helpers ## Legacy Helpers
Yomichan has historically used Handlebars templates to generate the HTML used on the search page and results popup. Yomichan has historically used Handlebars templates to generate the HTML used on the search page and results popup.

View File

@ -87,7 +87,9 @@ class AnkiTemplateRenderer {
['formatGlossary', this._formatGlossary.bind(this)], ['formatGlossary', this._formatGlossary.bind(this)],
['hasMedia', this._hasMedia.bind(this)], ['hasMedia', this._hasMedia.bind(this)],
['getMedia', this._getMedia.bind(this)], ['getMedia', this._getMedia.bind(this)],
['pronunciation', this._pronunciation.bind(this)] ['pronunciation', this._pronunciation.bind(this)],
['hiragana', this._hiragana.bind(this)],
['katakana', this._katakana.bind(this)]
]); ]);
this._templateRenderer.registerDataType('ankiNote', { this._templateRenderer.registerDataType('ankiNote', {
modifier: ({marker, commonData}) => this._ankiNoteDataCreator.create(marker, commonData), modifier: ({marker, commonData}) => this._ankiNoteDataCreator.create(marker, commonData),
@ -591,4 +593,16 @@ class AnkiTemplateRenderer {
return ''; return '';
} }
} }
_hiragana(context, ...args) {
const ii = args.length - 1;
const value = (ii > 0 ? args[0] : args[ii].fn(context));
return this._japaneseUtil.convertKatakanaToHiragana(value);
}
_katakana(context, ...args) {
const ii = args.length - 1;
const value = (ii > 0 ? args[0] : args[ii].fn(context));
return this._japaneseUtil.convertHiraganaToKatakana(value);
}
} }