### Install dependencies Source: https://github.com/yomidevs/yomitan/blob/master/README.md Initializes the project environment by installing required packages. ```bash npm ci ``` -------------------------------- ### Initialize Development Environment Source: https://github.com/yomidevs/yomitan/blob/master/CONTRIBUTING.md Commands to install dependencies and build the project after setting up Node.js and npm. ```bash npm ci npm run build ``` -------------------------------- ### Run Firefox for Android build and serve Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/npm-scripts.md Example command for building and serving the extension to Firefox for Android using environment variables. ```bash WEB_EXT_TARGET="firefox-android" WEB_EXT_ADB_DEVICE="emulator-5554" npm run build:serve:firefox-android ``` -------------------------------- ### Implement Capitalization Preprocessors Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Examples of text processors that modify string casing, utilizing boolean options to toggle behavior. ```js /** @type {import('language').TextProcessor} */ export const decapitalize = { name: "Decapitalize text", description: "CAPITALIZED TEXT → capitalized text", options: basicTextProcessorOptions, // [false, true] process: (str, setting) => (setting ? str.toLowerCase() : str), }; /** @type {import('language').TextProcessor} */ export const capitalizeFirstLetter = { name: "Capitalize first letter", description: "lowercase text → Lowercase text", options: basicTextProcessorOptions, // [false, true] process: (str, setting) => setting ? str.charAt(0).toUpperCase() + str.slice(1) : str, }; ``` -------------------------------- ### Run Playwright Tests Locally Source: https://github.com/yomidevs/yomitan/blob/master/CONTRIBUTING.md Commands to install browser dependencies, clone required test data, and execute Playwright tests. ```bash npx playwright install ``` ```bash git clone --branch dictionaries git@github.com:yomidevs/yomitan.git dictionaries ``` ```bash npx playwright test ``` -------------------------------- ### Implement Basic English Deinflection Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Example of a simple pluralization rule using suffixInflection. ```javascript // english-transforms.js import { suffixInflection } from "../language-transforms.js"; export const englishTransforms = { language: "en", conditions: {}, transforms: { plural: { name: "plural", description: "Plural form of a noun", rules: [suffixInflection("s", "", [], [])], }, }, }; ``` -------------------------------- ### get Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Retrieves a value from the custom state stack. ```APIDOC ## {{get name}} ### Description Gets a value from the custom state stack by its name. ### Parameters - **name** (string) - Required - The name of the variable to retrieve. ``` -------------------------------- ### Define deinflection rules with JSDoc Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Initial setup for deinflection rules using JSDoc annotations for basic type checking. ```javascript // english-transforms.js import { suffixInflection } from "../language-transforms.js"; /** @type {import('language-transformer').LanguageTransformDescriptor} */ export const englishTransforms = { language: "en", conditions: { n: { name: "Noun", isDictionaryForm: true, subConditions: ["np", "ns"], }, np: { name: "Noun plural", isDictionaryForm: true, }, ns: { name: "Noun singular", isDictionaryForm: true, }, }, transforms: { // omitted }, }; ``` -------------------------------- ### Retrieve state with get Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Fetches a value from the custom state stack by name. ```handlebars {{get "some-text"}} ``` ```html This is the value of some-text! ``` -------------------------------- ### property Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Repeatedly gets a property of an object. ```APIDOC ## {{property object property1 property2 ... propertyN}} ### Description Traverses an object by a chain of property names. ### Parameters - **object** (object) - Required - The initial object. - **propertyN** (string) - Required - A chain of property names to access. ``` -------------------------------- ### Build the project Source: https://github.com/yomidevs/yomitan/blob/master/README.md Compiles the project for testing or release purposes. ```bash npm run build ``` ```bash npm run-script build -- --all --version {version} ``` -------------------------------- ### Execute Project Tests Source: https://github.com/yomidevs/yomitan/blob/master/CONTRIBUTING.md Command to run the suite of unit and integration tests. ```bash npm test ``` -------------------------------- ### Execute npm script Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/npm-scripts.md Standard command format for running defined scripts. ```bash npm run ``` -------------------------------- ### Generate license report Source: https://github.com/yomidevs/yomitan/blob/master/README.md Creates or updates the project's license information in HTML format. ```bash npm run license-report:html ``` -------------------------------- ### Injecting Media Content with hasMedia and getMedia Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Use hasMedia to check for availability and getMedia to retrieve content. These helpers support various media types including audio, screenshots, and dictionary-specific files. ```handlebars {{#if (hasMedia "audio")}}The audio file name is: {{getMedia "audio"}}{{/if}} {{#if (hasMedia "screenshot")}}The screenshot file name is: {{getMedia "screenshot"}}{{/if}} {{#if (hasMedia "clipboardImage")}}The clipboard image file name is: {{getMedia "clipboardImage"}}{{/if}} {{#if (hasMedia "clipboardText")}}The clipboard text is: {{getMedia "clipboardText"}}{{/if}} {{#if (hasMedia "popupSelectionText")}}The popup selection text is: {{getMedia "popupSelectionText"}}{{/if}} {{#if (hasMedia "textFurigana" "日本語")}}This is an example of text with generated furigana: {{getMedia "textFurigana" "日本語" escape=false}}{{/if}} {{#if (hasMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary")}}The remapped file name for image.png is: {{getMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary"}}{{/if}} ``` -------------------------------- ### Convert text to katakana using Handlebars Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Demonstrates both inline and block syntax for converting hiragana strings to katakana. ```handlebars {{katakana "よみたん ヨミたん ヨミタン"}} {{#katakana}}よみたん ヨミたん ヨミタン{{/katakana}} ``` ```html ヨミタン ヨミタン ヨミタン ヨミタン ヨミタン ヨミタン ``` -------------------------------- ### Identify ADB device Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/npm-scripts.md Command to list connected devices for ADB configuration. ```bash adb devices ``` -------------------------------- ### Register a new language in language-descriptors.js Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Add a language object to the languageDescriptors array using ISO 639-1 and ISO 639-3 codes. ```js // language-descriptors.js { iso: 'nl', iso639_3: 'nld', name: 'Dutch', exampleText: 'lezen', textPreprocessors: capitalizationPreprocessors } ``` -------------------------------- ### Implement Deinflection Unit Tests Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Sets up a test suite for language transformers to verify term deinflection paths and rule chaining. ```javascript // english-transforms.test.js import { englishTransforms } from "../../ext/js/language/en/english-transforms.js"; import { LanguageTransformer } from "../../ext/js/language/language-transformer.js"; import { testLanguageTransformer } from "../fixtures/language-transformer-test.js"; const tests = [ { category: "plurals and possessive", valid: true, tests: [ { term: "cat", source: "cats", rule: "ns", reasons: ["plural"] }, { term: "cat", source: "cat's", rule: "ns", reasons: ["possessive"] }, { term: "cat", source: "cats'", rule: "ns", reasons: ["plural", "possessive"], }, ], }, ]; const languageTransformer = new LanguageTransformer(); languageTransformer.addDescriptor(englishTransforms); testLanguageTransformer(languageTransformer, tests); ``` -------------------------------- ### Formatting Pronunciation with pronunciation Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Generates an HTML string for pronunciation display based on the specified format, reading, and downstep position. ```handlebars {{~pronunciation format='text' reading='よむ' downstepPosition=1~}} ``` -------------------------------- ### Configure Git for SSH Commit Signing Source: https://github.com/yomidevs/yomitan/blob/master/CONTRIBUTING.md Commands to set the GPG format to SSH, specify the signing key path, and enable automatic commit signing. ```bash git config --global gpg.format ssh git config --global user.signingkey /path/to/key git config --global commit.gpgsign true ``` -------------------------------- ### Implement Bidirectional Conversion Preprocessor Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md A preprocessor that handles three-state settings to perform direct or inverse character replacements. ```js // from german-text-preprocessors.js /** @type {import('language').BidirectionalConversionPreprocessor} */ export const eszettPreprocessor = { name: 'Convert "ß" to "ss"', description: "ß → ss, ẞ → SS and vice versa", options: ["off", "direct", "inverse"], process: (str, setting) => { switch (setting) { case "off": return str; case "direct": return str.replace(/ẞ/g, "SS").replace(/ß/g, "ss"); case "inverse": return str.replace(/SS/g, "ẞ").replace(/ss/g, "ß"); } }, }; ``` -------------------------------- ### noop Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns the inner contents of the template without modification. ```APIDOC ## {{#noop}}content{{/noop}} ### Description No-op helper that returns the inner contents of the template. ``` -------------------------------- ### Format glossary entries Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts a raw glossary entry into an HTML content string, including images and structured content. ```handlebars {{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}} ``` ```html Here is the content of a gloss, which may include formatted HTML. ``` -------------------------------- ### Configure VSCode for Dictionary Schema Validation Source: https://github.com/yomidevs/yomitan/blob/master/docs/making-yomitan-dictionaries.md Add these settings to your VSCode settings.json to enable automatic validation of dictionary JSON files against official Yomitan schemas. ```json "json.schemas": [ { "fileMatch": ["index.json"], "url": "https://raw.githubusercontent.com/yomidevs/yomitan/refs/heads/master/ext/data/schemas/dictionary-index-schema.json" }, { "fileMatch": ["kanji_bank_*.json"], "url": "https://raw.githubusercontent.com/yomidevs/yomitan/refs/heads/master/ext/data/schemas/dictionary-kanji-bank-v3-schema.json" }, { "fileMatch": ["kanji_meta_bank_*.json"], "url": "https://raw.githubusercontent.com/yomidevs/yomitan/refs/heads/master/ext/data/schemas/dictionary-kanji-meta-bank-v3-schema.json" }, { "fileMatch": ["tag_bank_*.json"], "url": "https://raw.githubusercontent.com/yomidevs/yomitan/refs/heads/master/ext/data/schemas/dictionary-tag-bank-v3-schema.json" }, { "fileMatch": ["term_bank_*.json"], "url": "https://raw.githubusercontent.com/yomidevs/yomitan/refs/heads/master/ext/data/schemas/dictionary-term-bank-v3-schema.json" }, { "fileMatch": ["term_meta_bank_*.json"], "url": "https://raw.githubusercontent.com/yomidevs/yomitan/refs/heads/master/ext/data/schemas/dictionary-term-meta-bank-v3-schema.json" } ] ``` -------------------------------- ### join Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Joins multiple arguments into a single string using a specified separator, flattening any arrays. ```APIDOC ## {{join separator value1 value2 ...}} ### Description Joins the provided arguments into a single string with a separator, flattening any arguments that are arrays. ### Parameters - **separator** (string) - Required - The string used to separate values. - **valueN** (any) - Required - Individual values to join. ``` -------------------------------- ### set Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Assigns a value to the custom state stack. ```APIDOC ## {{set name value}} ### Description Assigns a value to the custom state stack. Can be used as a block helper or an inline helper. ### Parameters - **name** (string) - Required - The name of the variable to assign. - **value** (any) - Required - The value to assign to the variable. ``` -------------------------------- ### formatGlossary Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Formats a glossary entry into an HTML content string. ```APIDOC ## {{formatGlossary dictionary definitionEntry}} ### Description Formats a glossary entry to an HTML content string, handling image and structured-content generation. ### Parameters - **dictionary** (string) - Required - The dictionary the entry belongs to. - **definitionEntry** (object) - Required - The raw definition entry object. ``` -------------------------------- ### pronunciation Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts pronunciation information into a formatted HTML content string. ```APIDOC ## {{pronunciation}} ### Description Converts pronunciation information into a formatted HTML content string using the same layout as popup and search page dictionary entries. ### Syntax {{pronunciation format=string reading=string downstepPosition=integer [nasalPositions=array] [devoicePositions=array]}} ### Parameters - **format** (string) - Required - The format of the HTML ('text', 'graph', or 'position'). - **reading** (string) - Required - The kana reading of the term. - **downstepPosition** (integer) - Required - The mora position of the downstep. - **nasalPositions** (array) - Optional - Indices of mora with nasal pronunciation. - **devoicePositions** (array) - Optional - Indices of mora that are devoiced. ``` -------------------------------- ### Implement type-safe deinflection rules Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Enhanced configuration using a typedef to provide full autocompletion and type safety for condition keys. ```javascript // english-transforms.js import { suffixInflection } from "../language-transforms.js"; /** @typedef {keyof typeof conditions} Condition */ const conditions = { n: { name: "Noun", isDictionaryForm: true, subConditions: ["np", "ns"], }, np: { name: "Noun plural", isDictionaryForm: true, }, ns: { name: "Noun singular", isDictionaryForm: true, }, }; /** @type {import('language-transformer').LanguageTransformDescriptor} */ export const englishTransforms = { language: "en", conditions, transforms: { // omitted }, }; ``` -------------------------------- ### #scope Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Pushes a new variable scope to the custom state stack. ```APIDOC ## {{#scope}}content{{/scope}} ### Description Pushes a new variable scope to the custom state stack. Variable assignments are applied to the most recent scope, and lookups start from the most recent scope backwards. ``` -------------------------------- ### op Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Performs a unary, binary, or ternary operation on provided arguments. ```APIDOC ## {{op operator operand1 [operand2] [operand3]}} ### Description Performs a simple operation on one, two, or three arguments. If an unknown operator is specified, the undefined value is returned. ### Parameters - **operator** (string) - Required - One of the supported unary, binary, or ternary operators. - **operand1** (any) - Required - The first operand. - **operand2** (any) - Optional - The second operand. - **operand3** (any) - Optional - The third operand. ### Example {{#if (op "===" value1 value2)}}Values are equal{{/if}} ``` -------------------------------- ### #eachUpTo Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Iterates over an iterable up to a maximum count, similar to the built-in #each helper. ```APIDOC ## #eachUpTo ### Description 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}} ### Parameters - **iterable** (object) - Required - The object that should be looped over. - **maxCount** (number) - Optional - The maximum number of entries to loop over. ``` -------------------------------- ### hasMedia & getMedia Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Checks for and retrieves media content for a card. These functions are used together to request media and optional asynchronous content. ```APIDOC ## {{hasMedia}} & {{getMedia}} ### Description Checks to see if a certain type of media is available for a card and injects the relevant content. ### Syntax {{hasMedia type args...}} {{getMedia type args... [escape=true|false]}} ### Parameters - **type** (string) - Required - The type of media to check for (e.g., "audio", "screenshot", "clipboardImage", "clipboardText", "popupSelectionText", "textFurigana", "dictionaryMedia"). - **args** (any) - Optional - Additional arguments depending on the media type. - **escape** (boolean) - Optional - Whether the resulting text should be HTML-escaped. Defaults to true. ``` -------------------------------- ### Convert text to simplified furigana Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Transforms definitions or expression/reading pairs into a simplified bracketed furigana format. ```handlebars {{~furiganaPlain .~}} {{furiganaPlain "読む" "よむ"}} ``` ```html 読[よ]む ``` -------------------------------- ### Iterate with a limit using eachUpTo Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Loops over an iterable up to a specified maximum count, with an optional else block for empty or falsy inputs. ```handlebars {{~#eachUpTo someArray 5}}{{{.}}}
{{else}}Empty{{/mergeTags~}} ``` -------------------------------- ### Perform operations with op Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Executes unary, binary, or ternary operations on provided arguments. ```handlebars {{#if (op "===" value1 value2)}}Values are equal{{/if~}}
{{~#op "-" value1}}{{/op~}}
{{~op "?:" value1 "a" "b"}} ``` ```html Values are equal
-32
a ``` -------------------------------- ### Configure Font Family Source: https://github.com/yomidevs/yomitan/blob/master/ext/settings.html Specify custom font stacks for the Yomitan interface by providing a comma-separated list of font names. ```text "Noto Sans JP", "Meiryo", sans-serif ``` -------------------------------- ### concat Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Joins multiple arguments into a single string without flattening arrays. ```APIDOC ## {{concat value1 value2 ...}} ### Description Joins the provided arguments into a single string without flattening any arrays. ### Parameters - **valueN** (any) - Required - Values to join into the resulting string. ``` -------------------------------- ### Convert text to furigana Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Transforms definitions or expression/reading pairs into HTML ruby furigana representation. ```handlebars {{furigana .}} {{furigana "読む" "よむ"}} ``` ```html 読よむ ``` -------------------------------- ### Pass through content with noop Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns the inner contents of the template block unchanged. ```handlebars {{noop}}Unchanged content{{/noop}} ``` ```html Unchanged content ``` -------------------------------- ### Assign state with set Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Stores a value in the custom state stack using either block or inline syntax. ```handlebars {{#set "some-text"}}This is the value of some-text!{{/set~}} {{~set "some-number" 32}} ``` ```html ``` -------------------------------- ### hiragana Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts katakana text to hiragana. ```APIDOC ## {{hiragana}} ### Description Converts katakana text to hiragana. ### Syntax {{hiragana value [keepProlongedSoundMarks=true|false]}} {{#hiragana [keepProlongedSoundMarks=true|false]}}value{{/hiragana}} ### Parameters - **value** (string) - Required - The text to convert. - **keepProlongedSoundMarks** (boolean) - Optional - Whether the 'ー' character should be kept or converted to a vowel. Defaults to false. ``` -------------------------------- ### Join values with join Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Joins arguments into a single string using a separator, flattening any arrays. ```handlebars {{set "index" 32~}} {{~join "_" "yomitan" (get "index") "value"}} ``` ```html yomitan_32_value ``` -------------------------------- ### pitchCategories Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns an array of pitch categories for a specific term. ```APIDOC ## {{pitchCategories @root}} ### Description Returns an array representing the different pitch categories for a specific term. ### Parameters - **@root** (object) - Required - The root data object. ``` -------------------------------- ### getKanaMorae Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns an array of the mora for a kana string. ```APIDOC ## {{getKanaMorae kana-string}} ### Description Returns an array of the mora for a given kana string. ### Parameters - **kana-string** (string) - Required - The kana string to process. ``` -------------------------------- ### Define language types in language-descriptors.d.ts Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Provide type safety for the new language by defining its preprocessor configuration. ```ts // language-descriptors.d.ts nl: { pre: CapitalizationPreprocessors; } ``` -------------------------------- ### typeof Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns the type of a value. The block form always returns 'string'. ```APIDOC ## {{typeof value}} ### Description Returns the type of the provided value. When used as a block helper, it always returns 'string'. ### Syntax {{typeof value}} {{#typeof}}value{{/typeof}} ### Parameters - **value** (any) - Required - The value to check the type of. ``` -------------------------------- ### furiganaPlain Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts a definition or expression/reading pair to its simplified furigana representation. ```APIDOC ## {{furiganaPlain definition}} or {{furiganaPlain expression reading}} ### Description Converts a definition or expression/reading pair to its simplified furigana representation. ### Parameters - **definition** (string) - Optional - The definition to convert. - **expression** (string) - Optional - The expression to convert. - **reading** (string) - Optional - The reading to convert. ``` -------------------------------- ### Split kana into morae with getKanaMorae Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns an array of mora for a given kana string. ```handlebars {{#each (getKanaMorae "よみたん")}}{{{.}}}
{{/each}} ``` ```html よ
み
た
ん
``` -------------------------------- ### katakana Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts hiragana text to katakana using either a block or inline syntax. ```APIDOC ## katakana ### Description Converts hiragana text to katakana. ### Syntax `{{katakana text}}` `{{#katakana}}text{{/katakana}}` ### Parameters - **text** (string) - Required - The text to convert. ### Example ```handlebars {{katakana "よみたん ヨミたん ヨミタン"}} {{#katakana}}よみたん ヨミたん ヨミタン{{/katakana}} ``` ### Output ```html ヨミタン ヨミタン ヨミタン ヨミタン ヨミタン ヨミタン ``` ``` -------------------------------- ### Check pitch with isMoraPitchHigh Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Determines if a mora at a specific index has a high pitch based on the downstep position. ```handlebars {{#if (isMoraPitchHigh 1 2)}}High pitch{{else}}Low pitch{{/if}} ``` ```html High pitch ``` -------------------------------- ### furigana Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts a definition or expression/reading pair to its furigana representation. ```APIDOC ## {{furigana definition}} or {{furigana expression reading}} ### Description Converts a definition or expression/reading pair to its furigana representation. ### Parameters - **definition** (string) - Optional - The definition to convert. - **expression** (string) - Optional - The expression to convert. - **reading** (string) - Optional - The reading to convert. ``` -------------------------------- ### Debug objects with dumpObject Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts an object to a pretty-printed JSON string for debugging purposes. ```handlebars
{{dumpObject .}}
``` ```html
{
    "key": "value"
}
``` ```html { "key": "value" } ``` -------------------------------- ### Format multiline text Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Replaces newline characters within a block with HTML line break tags. ```handlebars {{#multiLine~}} some multiline text {{~/multiLine}} ``` ```html some
multiline
text ``` ```html some
multiline
text ``` -------------------------------- ### Update Plural Rule for Chaining Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Adding conditionIn to the plural rule to allow chaining with possessive rules. ```javascript { name: "plural", description: "Plural form of a noun", rules: [ suffixInflection("s", "", ["n"], ["n"]) ], }, ``` -------------------------------- ### Perform regex replacement Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Applies a regular expression to modify text content using standard JavaScript RegExp patterns. ```handlebars {{#regexReplace "\(([^)]*)\)" "$1" "g"~}}Here is (some) (text) (in) (parentheses){{~/regexReplace}} ``` ```html Here is some text in parentheses ``` -------------------------------- ### mergeTags Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Creates a set of all unique tags for the definition and returns a text representation of the tags separated by commas. ```APIDOC ## mergeTags ### Description 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}} ### Parameters - **definition** (object) - Required - The root definition object. - **isGroupMode** (boolean) - Optional - Whether or not the display mode is the 'group' mode. - **isMergeMode** (boolean) - Required - Whether or not the display mode is the 'merge' mode. ``` -------------------------------- ### regexReplace Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Uses a regular expression to replace a pattern with specified text. ```APIDOC ## {{#regexReplace regex replacement [flags]}}text{{/regexReplace}} ### Description Uses a regular expression to replace a pattern with the specified text. ### Parameters - **regex** (string) - Required - The raw string used to create the regular expression. - **replacement** (string) - Required - The text used to replace pattern matches. - **flags** (string) - Optional - Optional flags to pass to the RegExp constructor. ``` -------------------------------- ### regexMatch Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Uses a regular expression to return only the content that matches the pattern. ```APIDOC ## regexMatch ### Description 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]...}} ### Parameters - **regex** (string) - Required - The raw string used to create the regular expression. - **flags** (string) - Optional - Optional flags to pass to the RegExp constructor. - **text-to-modify** (string) - Required - The text that the regular expression is applied to. ``` -------------------------------- ### Add Invalid Deinflection Test Case Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Adds a test case to verify that specific invalid deinflection paths fail as expected. ```javascript { category: 'invalid deinflections', valid: false, tests: [ {term: 'boss', source: 'bo', rule: 'ns', reasons: ['plural', 'plural']}, ], }, ``` -------------------------------- ### Concatenate strings with concat Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Joins arguments into a single string without flattening arrays. ```handlebars {{set "index" 32~}} {{~concat "yomitan_" (get "index") "_value"}} ``` ```html yomitan_32_value ``` -------------------------------- ### Access object properties with property Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Traverses an object chain to retrieve a specific property. ```handlebars {{property someObject "field" 0 "toString"}} ``` ```html function toString() { [native code] } ``` -------------------------------- ### Retrieve pitch categories Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns an array of pitch categories for a term using the root data object. ```handlebars [{{#each (pitchCategories @root)}}{{.}}{{#unless @last}}, {{/unless}}{{/each}}] ``` ```html [heiban, kifuku] ``` -------------------------------- ### Merge tags with mergeTags Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Aggregates unique tags from a definition object into a comma-separated string. ```handlebars {{~mergeTags definition group merge~}} ``` -------------------------------- ### Manage variable scope with scope Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Creates a new variable scope where assignments are local to the block. ```handlebars {{~set "key" 32~}} {{~get "key"~}}, {{~#scope~}} {{~#get "key"~}}, {{~#set "key" 64~}} {{~#get "key"~}}, {{~/scope~}} {{~get "key"~}} ``` ```html 32,32,64,32 ``` -------------------------------- ### multiLine Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Replaces newline characters with a forced HTML line break
. ```APIDOC ## {{#multiLine}}text{{/multiLine}} ### Description Replaces newline characters within the block with a forced HTML line break
. ``` -------------------------------- ### Define Deinflection Rules Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Defines conditions and transformation rules for noun pluralization using the suffixInflection helper. ```javascript conditions: { n: { name: "Noun", isDictionaryForm: true, subConditions: ["np", "ns"], }, np: { name: "Noun plural", isDictionaryForm: true, }, ns: { name: "Noun singular", isDictionaryForm: true, }, }, transforms: { "plural": { name: "plural", description: "Plural form of a noun", rules: [ suffixInflection("s", "", ["np"], ["ns"]) ], }, }, ``` -------------------------------- ### Filter text with regexMatch Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Extracts content matching a regular expression pattern. The regex string is passed to the RegExp constructor. ```handlebars {{#regexMatch "\(([^)]*)\)" "g"~}}Here is (some) (text) (in) (parentheses){{~/regexMatch}} ``` -------------------------------- ### dumpObject Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts an object to a pretty-printed JSON string for debugging purposes. ```APIDOC ## {{dumpObject object}} ### Description Converts an object to a pretty-printed JSON string. This function is useful for debugging values when creating templates. ### Syntax {{dumpObject object}} ### Parameters - **object** (any) - Required - The object to convert. ``` -------------------------------- ### Apply Conditions to Deinflection Rules Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Restricting deinflection rules to specific parts of speech using conditions. ```javascript conditions: { n: { name: 'Noun', isDictionaryForm: true, }, }, transforms: { "plural": { name: "plural", description: "Plural form of a noun", rules: [ suffixInflection("s", "", [], ["n"]) ], }, }, ``` -------------------------------- ### Converting Text with hiragana Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts katakana to hiragana. The keepProlongedSoundMarks option determines if the prolonged sound mark is preserved or converted to a vowel. ```handlebars {{hiragana "よみたん ヨミたん ヨミタン"}} {{#hiragana}}よみたん ヨミたん ヨミタン{{/hiragana}} {{#hiragana}}ローマ字{{/hiragana}} {{#hiragana keepProlongedSoundMarks=true}}ローマ字{{/hiragana}} ``` -------------------------------- ### isMoraPitchHigh Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Determines if a mora has a high pitch. ```APIDOC ## {{isMoraPitchHigh index position}} ### Description Returns whether or not a mora will have a high pitch, given the index of the mora and the position of the downstep. ### Parameters - **index** (number) - Required - The index of the mora. - **position** (number) - Required - The position of the downstep. ``` -------------------------------- ### Check value type with typeof Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Returns the type of a value. The block form always returns 'string'. ```handlebars {{typeof "よみたん"}} {{typeof 1}} {{#typeof}}よみたん{{/typeof}} ``` ```html string number string ``` -------------------------------- ### Define Possessive Deinflection Rule Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md Adding a rule for possessive forms. ```javascript { name: "possessive", description: "Possessive form of a noun", rules: [ suffixInflection("'", "", [], ["n"]) ], }, ``` -------------------------------- ### Define a TextProcessor Type Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md The TypeScript interface for defining a text processor, which includes metadata and the processing function. ```ts // from language.d.ts export type TextProcessor = { name: string; description: string; options: TextProcessorOptions; process: TextProcessorFunction; }; ``` -------------------------------- ### spread Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts one or more iterables into a single array using the JavaScript spread operator. ```APIDOC ## spread ### Description 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}} ### Parameters - **iterableN** (object) - Required - A variable amount of iterable objects to combine into a single array. ``` -------------------------------- ### Define LanguageTransformDescriptor Types Source: https://github.com/yomidevs/yomitan/blob/master/docs/development/language-features.md TypeScript type definitions for the language transform structure. ```typescript // from language-transformer.d.ts export type LanguageTransformDescriptor = { language: string; conditions: ConditionMapObject; transforms: TransformMapObject; }; export type ConditionMapObject = { [type in TCondition]: Condition; }; export type TransformMapObject = { [name: string]: Transform; }; ``` -------------------------------- ### Combine iterables with spread Source: https://github.com/yomidevs/yomitan/blob/master/docs/templates.md Converts multiple iterables into a single array, similar to Array.concat. ```handlebars {{#each (spread array1 array2)}}{{{.}}}
{{/each}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.