Skip to content

Commit 2649116

Browse files
znzclaude
andcommitted
Fix title attribute unescaping to handle \\" and \" only
The previous unescape only handled \", missing \\. Use /\\(["\\])/ to correctly unescape both without affecting other backslash sequences like literal \n in samplecode labels. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8cc6bd1 commit 2649116

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/bitclust/markdown_to_rrd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def convert_code_block(line)
151151
lang = $2.empty? ? nil : $2
152152
end
153153
if line =~ /title="((?:[^"\\]|\\.)*)"/
154-
title = $1.gsub('\\"', '"')
154+
title = $1.gsub(/\\(["\\])/, '\1')
155155
end
156156

157157
if lang == 'ruby'

test/test_markdown_to_rrd.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ def test_code_block_without_language
108108
assert_equal expected, convert(md)
109109
end
110110

111+
def test_code_block_title_with_backslash
112+
md = "```ruby title=\"C:\\\\path\"\ncode\n```\n"
113+
expected = "\#@samplecode C:\\path\ncode\n\#@end\n"
114+
assert_equal expected, convert(md)
115+
end
116+
111117
def test_code_block_lang_without_title
112118
md = "```sh\necho hello\n```\n"
113119
expected = "//emlist[][sh]{\necho hello\n//}\n"

0 commit comments

Comments
 (0)