Opinionated and hacky Markdown formatter for dprint that follows Japanese-specific rules, based on the dprint/dprint-plugin-markdown v0.17.8.
The plugin will insert a space between a Japanese character and a non-Japanese character, except in the following opinionated rules:
- The previous character is Japanese, and the current character is one of
()*/:_`~
. - The previous character is one of
()*/_`~
, and the current character is Japanese. - Either the previous or current character is a Japanese symbol or punctuation mark.
The plugin will also replace the following characters with their half-width counterparts:
"#$%&'(),./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^`abcdefghijklmnopqrstuvwxyz{|}
and full-width whitespace
See Text_Japanese.txt and Text_Japanese_Zenkaku.txt for how the plugin will work.
Please note that inserting a space in such a way is a controversial topic. See Do not insert whitespaces between latin and cj letters · Issue #6385 · prettier/prettier for the discussion in the context of Prettier.
The plugin will determine whether a character is Japanese or Japanese symbols and punctuation based on the Unicode code points. See the following sections.
Description | Range |
---|---|
Hiragana | \u{3041}..=\u{3096} , \u{3099}..=\u{309F} |
Kana Extended-A | \u{1B100}..=\u{1B12F} |
Kana Extended-B | \u{1AFF0}..=\u{1AFFF} |
Kana Supplement | \u{1B000}..=\u{1B0FF} |
Small Kana Extension | \u{1B130}..=\u{1B16F} |
Katakana | \u{30A0}..=\u{30FF} |
CJK Unified Ideographs | \u{4E00}..=\u{9FFF} |
CJK Unified Ideographs Extension A | \u{3400}..=\u{4DBF} |
CJK Unified Ideographs Extension B | \u{20000}..=\u{2A6DF} |
CJK Unified Ideographs Extension C | \u{2A700}..=\u{2B739} |
CJK Unified Ideographs Extension D | \u{2B740}..=\u{2B81D} |
CJK Unified Ideographs Extension E | \u{2B820}..=\u{2CEA1} |
CJK Unified Ideographs Extension F | \u{2CEB0}..=\u{2EBE0} |
CJK Unified Ideographs Extension G | \u{30000}..=\u{3134A} |
CJK Unified Ideographs Extension H | \u{31350}..=\u{323AF} |
CJK Unified Ideographs Extension I | \u{2EBF0}..=\u{2EE5D} |
CJK Compatibility Ideographs | \u{F900}..=\u{FAFF} |
CJK Compatibility Ideographs Supplement | \u{2F800}..=\u{2FA1F} |
Symbols and punctuation (see table below) |
Description | Range |
---|---|
CJK Symbols and Punctuation | \u{3000}..=\u{303F} |
Halfwidth and Fullwidth Forms | \u{FF01}..=\u{FF60} |
Katakana Middle Dot | \u{30fb} |
To build a .wasm
file, you have to install wasm32-unknown-unknown
target for Rust. This can be done using the following command:
$ rustup target add wasm32-unknown-unknown
Then, you can build the .wasm
file using the following command:
$ cargo build --release --target=wasm32-unknown-unknown --features="wasm"
After the build, the .wasm
file will be located at target/wasm32-unknown-unknown/release/dprint_plugin_markdown_ja.wasm
. You can copy this file to the directory of yor choice and use it with dprint
.
There are no additional configuration options specific to this plugin, but the configuration key is markdownJa
instead of markdown
. See Markdown Plugin for available options.
{
/// ... other configurations ...
"markdownJa": {
"textWrap": "maintain",
"emphasisKind": "underscores",
"strongKind": "asterisks"
},
"plugins": [
"/absolute/path/to/dprint_plugin_markdown_ja.wasm"
]
/// ... other configurations ...
}
MIT as the original plugin. See LICENSE for more information.
dprint and dprint/dprint-plugin-markdown, obviously.