Skip to content

Commit d3bd747

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 d3bd747

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,42 @@ 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+
# Test case for GitHub issue #1395
1162+
# Backslashes in code spans should be rendered consistently
1163+
# between plain text and table cells
1164+
doc = parse <<~MD
1165+
Plain text: `$\\\\` and `$\\\\ ` should work.
1166+
1167+
| Context | Code | Expected |
1168+
|---------|------|----------|
1169+
| Plain | `$\\\\` | Should show backslash |
1170+
| Escaped | `$\\\\ ` | Should show backslash space |
1171+
| Multiple| `\\\\n\\\\t` | Should show backslashes |
1172+
MD
1173+
1174+
head = %w[Context Code Expected]
1175+
align = [nil, nil, nil]
1176+
1177+
# Expected behavior: backslashes in code spans should be preserved
1178+
# in table cells just like in plain text
1179+
body = [
1180+
['Plain', '<code>$\\\\</code>', 'Should show backslash'],
1181+
['Escaped', '<code>$\\\\</code>', 'Should show backslash space'],
1182+
['Multiple', '<code>\\\\n\\\\t</code>', 'Should show backslashes'],
1183+
]
1184+
1185+
expected_table = @RM::Table.new(head, align, body)
1186+
1187+
# The document should contain a paragraph with inline code, then the table
1188+
expected = doc(
1189+
para('Plain text: <code>$\\\\</code> and <code>$\\\\</code> should work.'),
1190+
expected_table
1191+
)
1192+
1193+
assert_equal expected, doc
1194+
end
1195+
11601196
def parse(text)
11611197
@parser.parse text
11621198
end

0 commit comments

Comments
 (0)