Skip to main content

mdit-py-cjk-friendly

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

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

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 は本家プロジェクトのプラグインをどうぞ)。

ふりがな(ルビ)— オプション

構文の追加になるため、別プラグイン ruby として opt-in で提供する (でんでんマークダウン形式):

from mdit_py_cjk_friendly import cjk_friendly, ruby

md = MarkdownIt("commonmark").use(cjk_friendly).use(ruby)
md.render("{漢字|かんじ}")          # → <ruby>漢字<rp>(</rp><rt>かんじ</rt><rp>)</rp></ruby>
md.render("{東京|とう|きょう}")      # → モノルビ (読みの数=文字数のとき)
  • 読みの数が文字数と合わない・空の要素がある場合は変換しない(推測しない)
  • \{ でエスケープ。コードスパン・コードブロック内は変換されない
  • <rp> 括弧つきで出力するので、ルビ非対応の環境では「漢字(かんじ)」に落ちる

傍点・傍線(text-emphasis)— オプション

でんでんマークダウンには圏点専用の記法が無く、*text* を縦書き時のみ 圏点表示する仕様しか持たない(種別を区別できない)。傍点・傍線を種別込みで 書き分けたい場合に、Pandoc 風のクラス付きスパンを別プラグイン bouten として opt-in で提供する:

from mdit_py_cjk_friendly import cjk_friendly, bouten

md = MarkdownIt("commonmark").use(cjk_friendly).use(bouten)
md.render("[邪智暴虐]{.sesame_dot}")      # → <em class="sesame_dot">邪智暴虐</em>
md.render("[あ]{.underline_double}")      # → <em class="underline_double">あ</em>
  • クラス名 1 個(英字始まり)を <em class> に透過するだけ。見た目 (どのクラスがゴマ点・二重傍線か)は CSS が定める
  • ] の直後が {.class} でなければ何もしない。リンク [x](y) や 素の [x] を壊さない。inner はプレーンテキスト扱い(推測しない)
  • */**(強調・太字)は素の Markdown で足りるので対象外
  • 青空文庫の種別に対応するクラス例: 傍点 sesame_dot / white_sesame_dot / black_circle / white_circle / bullseye / fisheye / saltire / black_up-pointing_triangle / white_up-pointing_triangle、傍線 underline_solid / underline_double / underline_dotted / underline_dashed / underline_wave(上側は overline_*)

対応する CSS の例(縦書き):

em.sesame_dot { font-style: normal;
  text-emphasis: filled sesame; -webkit-text-emphasis: filled sesame; }
em[class^="underline_"] { font-style: normal; text-decoration: underline; }

補足

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

ライセンス

MIT

Release files for mdit-py-cjk-friendly 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdit-py-cjk-friendly 0.3.0
File Size Uploaded
mdit_py_cjk_friendly-0.3.0.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mdit-py-cjk-friendly 0.3.0
File Interpreter ABI Platform
mdit_py_cjk_friendly-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / mdit_py_cjk_friendly-0.3.0.tar.gz

Download URL mdit_py_cjk_friendly-0.3.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b5f590adbbb5529e1f640788763764bbb3b798a6f760c463c41af3d6951b36f5
BLAKE2b-256 checksum
How to use checksums
c78cedbc883de1e957b7cf2eaf5fef71016724b28377bca154016806169b77f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 11, 2026.

Transparency log

Release files / mdit_py_cjk_friendly-0.3.0-py3-none-any.whl

Download URL mdit_py_cjk_friendly-0.3.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd8ee19dde9292b1db70bf047eb860c7e8719855452fa483efdee3923d80bd6d
BLAKE2b-256 checksum
How to use checksums
4e4840549b5e757a7974d87a9e7e083604c009f047fa1fdc3920f4079907d7aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page