From 00a468d3b3bd3c3fb0c9461a43a6634b8bb16d03 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Tue, 14 Jul 2026 22:11:42 +0900 Subject: [PATCH] =?UTF-8?q?[[ISO:8601]]/[[JIS:X=200301]]=20=E3=82=92?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=AF=E3=81=AB=E3=81=9B=E3=81=9A=E5=B9=B3?= =?UTF-8?q?=E6=96=87=E3=81=A7=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BitClust には ISO/JIS へのリンク機能がないため、Date/DateTime の ドキュメントにある [[ISO:8601]] や [[JIS:X 0301]] という記法がリンクに ならず、生の角括弧のまま表示されていた。リンクは諦めて、それぞれ 「ISO 8601」「JIS X 0301」という平文で表示するようにする。凍結された 古いバージョン(RD ソースを編集できない)にも効く。 - StandardRef で [[ISO:...]]/[[JIS:...]] を捕捉する。引数に空白を含む JIS X 0301 も拾えるよう、既存の BracketLink とは別の正規表現にする - standard_ref で scheme 名と引数を空白区切りの平文に変換する fix rurema/bitclust#236 Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/bitclust/rdcompiler.rb | 16 +++++++++++++--- sig/bitclust/rdcompiler.rbs | 4 ++++ test/test_rdcompiler.rb | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/bitclust/rdcompiler.rb b/lib/bitclust/rdcompiler.rb index aecc1a0..eba7182 100644 --- a/lib/bitclust/rdcompiler.rb +++ b/lib/bitclust/rdcompiler.rb @@ -451,21 +451,31 @@ def method_signature(sig_line, first) end BracketLink = /\[\[[\w-]+?:[!-~]+?(?:\[\] )?\]\]/n + # BitClust には ISO/JIS へのリンク機能がないため、[[ISO:8601]]/[[JIS:X 0301]] は + # リンクにせず平文で表示する (rurema/bitclust#236)。引数に空白を含む JIS も拾う。 + StandardRef = /\[\[(?:ISO|JIS):[!-~][!-~ ]*?\]\]/n NeedESC = /[&"<>]/ def compile_text(str) escape_table = HTMLUtils::ESC - str.gsub(/(#{NeedESC})|(#{BracketLink})/o) { + str.gsub(/(#{NeedESC})|(#{StandardRef})|(#{BracketLink})/o) { # @type var char: '&' | '"' | '<' | '>' if char = _ = $1 then escape_table[char] - elsif tok = $2 then bracket_link(tok[2..-3] || raise) - elsif tok = $3 then seems_code(tok) + elsif tok = $2 then standard_ref(tok[2..-3] || raise) + elsif tok = $3 then bracket_link(tok[2..-3] || raise) else raise 'must not happen' end } end + def standard_ref(link) + # 例: "ISO:8601" -> "ISO 8601", "JIS:X 0301" -> "JIS X 0301" + type, _arg = link.split(':', 2) + arg = _arg&.strip or raise + escape_html("#{type} #{arg}") + end + def bracket_link(link, label = nil, frag = nil) type, _arg = link.split(':', 2) arg = _arg&.rstrip or raise diff --git a/sig/bitclust/rdcompiler.rbs b/sig/bitclust/rdcompiler.rbs index 5b232a0..406f7c3 100644 --- a/sig/bitclust/rdcompiler.rbs +++ b/sig/bitclust/rdcompiler.rbs @@ -118,10 +118,14 @@ module BitClust BracketLink: ::Regexp + StandardRef: ::Regexp + NeedESC: ::Regexp def compile_text: (String str) -> String + def standard_ref: (String link) -> String + def bracket_link: (String link, ?String? label, ?String? frag) -> String def protect: (String src) { () -> String } -> String diff --git a/test/test_rdcompiler.rb b/test/test_rdcompiler.rb index cc0013a..9a402e6 100644 --- a/test/test_rdcompiler.rb +++ b/test/test_rdcompiler.rb @@ -706,6 +706,8 @@ def test_invalid_case "man header" => ['[[man:sys/socket.h(header)]]', 'sys/socket.h(header)'], "man system call" => ['[[man:fopen(3linux)]]', 'fopen(3linux)'], "RFC" => ['[[RFC:2822]]', '[RFC2822]'], + "ISO standard" => ['[[ISO:8601]]', 'ISO 8601'], + "JIS standard" => ['[[JIS:X 0301]]', 'JIS X 0301'], "special var $~" => ['[[m:$~]]', '$~'], "special var $," => ['[[m:$,]]', '$,'], "extra close bracket" => ['[[c:String]]]', 'String]'],