Rouge を導入して ruby 以外の言語のシンタックスハイライトに対応する#223
Merged
Merged
Conversation
コードフェンスの言語指定は ruby だけがハイライトされ、他の言語は 素通し(しかも HTML エスケープなし)だった。 - Rouge を bitclust-core の依存に追加。lang 指定付きコードブロックの ハイライトを共通ヘルパ highlight_source に集約(rd の //emlist[][lang] と md のコードフェンスの両方) - 言語の解決は Rouge::Lexer.find に委ね、解決先が Ruby lexer の場合 (rb などの alias を含む)は従来どおり構文チェックを兼ねる Ripper ベースの SyntaxHighlighter を使う - その他の言語は Rouge::Formatters::HTML でハイライト。出力クラス名は Pygments 互換なので既存の syntax-highlight.css がそのまま効く (不足していた cpf / pi のみ追記) - Rouge が知らない言語はエスケープのみで出力。従来この経路と ruby の 構文エラー時フォールバックはエスケープされずに出力されていたのを修正 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
znz
added a commit
to znz/doctree
that referenced
this pull request
Jul 11, 2026
メソッド属性行 {: ...} 対応(rurema/bitclust#224)と Rouge 依存
(rurema/bitclust#223)を含む master に更新する。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
解決したい問題
#161 のフォローアップです。コードフェンスの言語指定は
rubyだけがハイライトされ、他の言語(
c、html、shなど)は素通しでした。しかもこの経路はHTML エスケープもされていなかったため、
<を含むコードが壊れて表示される潜在バグがありました(現在 doctree に非 ruby の言語タグ付きブロックが無いため未発現)。
変更内容
bitclust-coreの runtime 依存に追加highlight_sourceに集約(rd の
//emlist[][lang]と md のコードフェンスの両経路)Rouge::Lexer.findに委任:rbなどの alias を含む)→ 従来どおり構文チェックを兼ねる Ripper ベースの
SyntaxHighlighterRouge::Formatters::HTMLでハイライト。出力クラス名は Pygments 互換なので既存の
syntax-highlight.cssがそのまま効きます(不足していた
cpf/piの2クラスのみ追記)ruby の構文エラー時フォールバックも同様に修正)
表示の変化
```c/```sh/```yaml/```htmlなどが色付きになります```rbが ruby として(Ripper 実装で)ハイライトされるようになります```textは Rouge の PlainText lexer 経由でエスケープのみ(従来どおり無色)今後 doctree 側でフェンスに言語タグを付けていくと効き始めます
テスト
TestMDCompilerRougeHighlightを追加: C のハイライト・rbalias が Ripper 実装に委譲されること・未知言語のエスケープ・text の無色・rd/md の等価性の5ケース
ruby test/run_test.rb全件パス🤖 Generated with Claude Code