Skip to main content

markdown-it-py plugin that makes CommonMark friendly to Japanese/Chinese/Korean: no spurious spaces at soft line breaks, working emphasis next to full-width punctuation.

Project description

mdit-py-cjk-friendly

日本語 | English | 繁體中文 | 한국어

markdown-it-py を 日本語・中国語・韓国語 (CJK) フレンドリーにするプラグイン。

# PyPI 公開までは GitHub から:
pip install "mdit-py-cjk-friendly @ git+https://github.com/aiseed-dev/mdit-py-cjk-friendly.git"
# PyPI 公開後: pip install mdit-py-cjk-friendly
from markdown_it import MarkdownIt
from mdit_py_cjk_friendly import cjk_friendly

md = MarkdownIt("commonmark").use(cjk_friendly)

md.render("これは**「重要」**です。")
# <p>これは<strong>「重要」</strong>です。</p>

md.render("これは長い文章なので\n途中で改行しています。")
# <p>これは長い文章なので途中で改行しています。</p>   (不要な空白が入らない)

直る問題

CommonMark は空白で単語を区切る言語を前提に設計されており、 CJK テキストでは有名な問題が2つ起きる:

  1. 文中改行が空白になる — Markdown ソースを日本語文の途中で改行すると、 描画後に不要な半角スペースが入る。本プラグインは改行の前後がともに CJK 文字なら詰めて結合する (英文の折り返しは従来どおり)。
  2. 全角約物に隣接した強調が効かない**「重要」**です は CommonMark の flanking 規則で不成立になりリテラルの ** が残る。本プラグインは flanking 判定で CJK 文字を punctuation 互換として扱い、パーサレベルで 解決する (コードスパン・コードブロックには影響しない)。

強調の挙動は CommonMark CJK-friendly 仕様ドラフト の考え方に従った、markdown-it-py 向けの独立・簡易実装です (JavaScript は本家プロジェクトのプラグインをどうぞ)。

補足

  • 効くのは .use(cjk_friendly) したパーサだけ。同一プロセスの他の MarkdownIt インスタンスは上流と完全に同じ挙動を保つ
  • markdown-it-py 2.x / 3.x 対応

ライセンス

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdit_py_cjk_friendly-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdit_py_cjk_friendly-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file mdit_py_cjk_friendly-0.1.1.tar.gz.

File metadata

  • Download URL: mdit_py_cjk_friendly-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mdit_py_cjk_friendly-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1a866d1c46ba73bc8d15d472ceda4d2a7a9ecd722e7a89e07e77a418438980fd
MD5 0a54c6c0e914699156a175c9677098af
BLAKE2b-256 de6f455c12bc1f7fa64fe99f7a5f829ebba3ed0304709af6f398dafb853e80eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdit_py_cjk_friendly-0.1.1.tar.gz:

Publisher: publish.yml on aiseed-dev/mdit-py-cjk-friendly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mdit_py_cjk_friendly-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mdit_py_cjk_friendly-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e4c7e05747282642098b43dd4632462da11e2e5d5d8ca8b84e7baf7fad7f43e
MD5 294316e11ee3a05306f1132390a1275e
BLAKE2b-256 bb7d32e2287c5b53a2e254d0365ac3ae507344bc918e6ba10461e40eb5b5bdbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdit_py_cjk_friendly-0.1.1-py3-none-any.whl:

Publisher: publish.yml on aiseed-dev/mdit-py-cjk-friendly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page