Skip to content

Commit c2ebbe6

Browse files
committed
Fix backslash handling in table cell code spans
Only strip escaped pipe characters in table cells, preserving other backslashes for proper markdown processing in code spans.
1 parent 6639fe1 commit c2ebbe6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/rdoc/markdown.kpeg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ TableRow = ( ( TableItem:item1 TableItem2*:items { [item1, *items] } ):row | Tab
12531253
{ row }
12541254
TableItem2 = "|" TableItem
12551255
TableItem = < /(?:\\.|[^|\n])+/ >
1256-
{ text.strip.gsub(/\\(.)/, '\1') }
1256+
{ text.strip.gsub(/\\([|])/, '\1') }
12571257

12581258
TableLine = ( ( TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] } ):line | TableAlign2+:line ) "|"? @Newline
12591259
{ line }

test/rdoc/rdoc_markdown_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,36 @@ def test_gfm_table_with_links_and_code
11571157
assert_equal expected, doc
11581158
end
11591159

1160+
def test_gfm_table_with_backslashes_in_code_spans
1161+
doc = parse <<~MD
1162+
Plain text: `$\\\\` and `$\\\\ ` should work.
1163+
1164+
| Context | Code | Expected |
1165+
|---------|------|----------|
1166+
| Plain | `$\\\\` | Should show backslash |
1167+
| Escaped | `$\\\\ ` | Should show backslash |
1168+
| Multiple| `\\\\n\\\\t` | Should show backslashes |
1169+
MD
1170+
1171+
head = %w[Context Code Expected]
1172+
align = [nil, nil, nil]
1173+
1174+
body = [
1175+
['Plain', '<code>$\\\\</code>', 'Should show backslash'],
1176+
['Escaped', '<code>$\\\\</code>', 'Should show backslash'],
1177+
['Multiple', '<code>\\\\n\\\\t</code>', 'Should show backslashes'],
1178+
]
1179+
1180+
expected_table = @RM::Table.new(head, align, body)
1181+
1182+
expected = doc(
1183+
para('Plain text: <code>$\\\\</code> and <code>$\\\\</code> should work.'),
1184+
expected_table
1185+
)
1186+
1187+
assert_equal expected, doc
1188+
end
1189+
11601190
def parse(text)
11611191
@parser.parse text
11621192
end

0 commit comments

Comments
 (0)