Skip to content

Commit 39f5a2d

Browse files
authored
Fix backslash handling in table cell code spans (#1400)
Only strip escaped pipe characters in table cells, preserving other backslashes for proper markdown processing in code spans. Fixes #1395 ### Before <img width="40%" alt="Screenshot 2025-08-11 at 14 02 11" src="https://github.com/user-attachments/assets/8b75766b-bcff-40eb-b29b-d098d949577f" /> ### After <img width="40%" alt="Screenshot 2025-08-11 at 14 02 18" src="https://github.com/user-attachments/assets/dd28681d-41c1-44ce-a03d-d335ac21d7d6" />
1 parent 6639fe1 commit 39f5a2d

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)