From 4f4d9aa856eed8771c7dd5e1dc7439d4310b8c26 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Wed, 15 Jul 2026 01:43:42 +0900 Subject: [PATCH] =?UTF-8?q?dlist=20=E3=81=AE=E7=94=A8=E8=AA=9E=E3=81=AB=20?= =?UTF-8?q?{#id}=20=E3=81=A7=E3=82=A2=E3=83=B3=E3=82=AB=E3=83=BC=E3=82=92?= =?UTF-8?q?=E4=BB=98=E3=81=91=E3=82=89=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Markdown の定義リスト `- **term**:` の用語末尾に `{#id}` を書けるようにし、 その id を
の id 属性として出力する。用語集(doc/glossary)の各用語へ 直接リンクできるようにするための機能追加(rurema/doctree#2634 のため)。 - DLIST_RE に任意の `{#id}` を追加し、id を $2 で拾う - dt(s, id) に id 引数を追加し、id があれば `
` を出力 - 通常の dlist(id 無し)は従来どおり id 無しの
- RBS(dt)更新、test_mdcompiler にアンカー付き dlist のテストを追加 Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/bitclust/mdcompiler.rb | 9 ++++++--- lib/bitclust/rdcompiler.rb | 4 ++-- sig/bitclust/rdcompiler.rbs | 2 +- test/test_mdcompiler.rb | 12 ++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/bitclust/mdcompiler.rb b/lib/bitclust/mdcompiler.rb index 4cec201..cb99991 100644 --- a/lib/bitclust/mdcompiler.rb +++ b/lib/bitclust/mdcompiler.rb @@ -49,7 +49,9 @@ def signature_re INDENTED_FENCE_RE = /\A([ \t]+)(`{3,})/ # dd 段落の継続行(インデント行。ただしインデントフェンスの手前で止まる) DD_TEXT_RE = /\A[ \t](?![ \t]*`{3})/ - DLIST_RE = /\A- \*\*(.+?)\*\*:(?:\s|$)/ + # 用語の後ろに {#id} があればアンカー id として扱う(用語集の各用語への + # リンク用。rurema/doctree#2634)。id は $2 に入る。 + DLIST_RE = /\A- \*\*(.+?)\*\*:(?:[ \t]*\{#([\w-]+)\})?(?:\s|$)/ INFO_RE = /\A- \*\*(?:param|arg|return|raise)\*\*/ SEE_RE = /\A- \*\*SEE\*\*/ # @undef など変換器が生のまま渡す未知メタデータ @@ -271,12 +273,13 @@ def dlist # GFM モード: `term` のコードスパンは として描画し、 # 中身の参照はその中で解決する(...。spec/eval) term = ($1 || raise) + id = $2 # {#id} があれば dt にアンカーを付ける(term の再マッチ前に退避) if gfm? && term =~ /\A`(.+)`\z/ inner = ($1 || raise).strip - line dt("#{rd_compile_text(MarkdownToRRD.restore_inline(inner))}") + line dt("#{rd_compile_text(MarkdownToRRD.restore_inline(inner))}", id) else term = strip_code_span(term).strip - line dt(compile_text(term)) + line dt(compile_text(term), id) end inline = l.sub(DLIST_RE, '').strip @f.ungets(" #{inline}\n") unless inline.empty? diff --git a/lib/bitclust/rdcompiler.rb b/lib/bitclust/rdcompiler.rb index eba7182..1d47d83 100644 --- a/lib/bitclust/rdcompiler.rb +++ b/lib/bitclust/rdcompiler.rb @@ -273,8 +273,8 @@ def dd_without_p line '' end - def dt(s) - "
#{s}
" + def dt(s, id = nil) + id ? %Q(
#{s}
) : "
#{s}
" end def stop_on_syntax_error? diff --git a/sig/bitclust/rdcompiler.rbs b/sig/bitclust/rdcompiler.rbs index 406f7c3..750dd83 100644 --- a/sig/bitclust/rdcompiler.rbs +++ b/sig/bitclust/rdcompiler.rbs @@ -81,7 +81,7 @@ module BitClust # empty lines do not separate paragraphs. def dd_without_p: () -> void - def dt: (String s) -> String + def dt: (String s, ?String? id) -> String METHOD_ATTRIBUTE_LINE_RE: ::Regexp diff --git a/test/test_mdcompiler.rb b/test/test_mdcompiler.rb index 9edd9e7..cb7752a 100644 --- a/test/test_mdcompiler.rb +++ b/test/test_mdcompiler.rb @@ -158,6 +158,18 @@ def test_dlist RD end + def test_dlist_term_anchor + # 用語の後ろの {#id} は dt のアンカー id になる(用語集の各用語リンク用, rurema/doctree#2634) + html = @md.compile("- **アリティー**: {#arity}\n- **`arity`**:\n 仮引数の数。\n") + assert_include(html, '
アリティー
') + # {#id} が無い項目には id は付かない + assert_not_include(html, '
arity') + # 通常の dlist は従来どおり id 無し + plain = @md.compile("- **foo**:\n bar\n") + assert_include(plain, '
foo
') + assert_not_include(plain, '
Integer