Skip to content

Commit 00a468d

Browse files
znzclaude
andcommitted
[[ISO:8601]]/[[JIS:X 0301]] をリンクにせず平文で表示する
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 #236 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 83ab432 commit 00a468d

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

lib/bitclust/rdcompiler.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,31 @@ def method_signature(sig_line, first)
451451
end
452452

453453
BracketLink = /\[\[[\w-]+?:[!-~]+?(?:\[\] )?\]\]/n
454+
# BitClust には ISO/JIS へのリンク機能がないため、[[ISO:8601]]/[[JIS:X 0301]] は
455+
# リンクにせず平文で表示する (rurema/bitclust#236)。引数に空白を含む JIS も拾う。
456+
StandardRef = /\[\[(?:ISO|JIS):[!-~][!-~ ]*?\]\]/n
454457
NeedESC = /[&"<>]/
455458

456459
def compile_text(str)
457460
escape_table = HTMLUtils::ESC
458-
str.gsub(/(#{NeedESC})|(#{BracketLink})/o) {
461+
str.gsub(/(#{NeedESC})|(#{StandardRef})|(#{BracketLink})/o) {
459462
# @type var char: '&' | '"' | '<' | '>'
460463
if char = _ = $1 then escape_table[char]
461-
elsif tok = $2 then bracket_link(tok[2..-3] || raise)
462-
elsif tok = $3 then seems_code(tok)
464+
elsif tok = $2 then standard_ref(tok[2..-3] || raise)
465+
elsif tok = $3 then bracket_link(tok[2..-3] || raise)
463466
else
464467
raise 'must not happen'
465468
end
466469
}
467470
end
468471

472+
def standard_ref(link)
473+
# 例: "ISO:8601" -> "ISO 8601", "JIS:X 0301" -> "JIS X 0301"
474+
type, _arg = link.split(':', 2)
475+
arg = _arg&.strip or raise
476+
escape_html("#{type} #{arg}")
477+
end
478+
469479
def bracket_link(link, label = nil, frag = nil)
470480
type, _arg = link.split(':', 2)
471481
arg = _arg&.rstrip or raise

sig/bitclust/rdcompiler.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ module BitClust
118118

119119
BracketLink: ::Regexp
120120

121+
StandardRef: ::Regexp
122+
121123
NeedESC: ::Regexp
122124

123125
def compile_text: (String str) -> String
124126

127+
def standard_ref: (String link) -> String
128+
125129
def bracket_link: (String link, ?String? label, ?String? frag) -> String
126130

127131
def protect: (String src) { () -> String } -> String

test/test_rdcompiler.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ def test_invalid_case
706706
"man header" => ['[[man:sys/socket.h(header)]]', '<a class="external" href="http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html">sys/socket.h(header)</a>'],
707707
"man system call" => ['[[man:fopen(3linux)]]', '<a class="external" href="http://man7.org/linux/man-pages/man3/fopen.3.html">fopen(3linux)</a>'],
708708
"RFC" => ['[[RFC:2822]]', '<a class="external" href="https://tools.ietf.org/html/rfc2822">[RFC2822]</a>'],
709+
"ISO standard" => ['[[ISO:8601]]', 'ISO 8601'],
710+
"JIS standard" => ['[[JIS:X 0301]]', 'JIS X 0301'],
709711
"special var $~" => ['[[m:$~]]', '<a href="dummy/method/Kernel/v/=7e">$~</a>'],
710712
"special var $," => ['[[m:$,]]', '<a href="dummy/method/Kernel/v/=2c">$,</a>'],
711713
"extra close bracket" => ['[[c:String]]]', '<a href="dummy/class/String">String</a>]'],

0 commit comments

Comments
 (0)