Author Build Commit PR
flavorjones 23643 cb48a80 n/a
Repo Branch
rails/rails main
Message
Fix `to_markdown` code spans broken by tables and adjacent code (#58956) * Strip whitespace from `to_markdown` code spans in table cells kramdown rebuilt a table cell's code span with one backtick when the code started with two or more spaces, a tab, VT or FF. The span then did not open, and kramdown parsed the code as Markdown, rendering links that `#visit_a` would have dropped. Strip leading and trailing whitespace from code spans inside a table row. * Document that `to_markdown` link sanitization is best effort The docs on both `to_markdown` methods did not say that HTML rendered from the returned Markdown could contain unsafe links. Add a note saying so. * Separate adjacent `to_markdown` code spans with a space When two code elements were adjacent, the delimiters of their code spans touched. CommonMark renderers read the touching delimiters as one backtick string, so neither span closed, and they parsed the code text as Markdown, which could render a link. Put a space between a part ending in a backtick and a part starting with one. * Escape pipes in `to_markdown` code spans in table cells GFM ends a table cell at any unescaped pipe, including one inside a code span. A pipe in a table cell's code therefore split the cell, and the code text after the pipe was parsed as Markdown. In a table row, escape pipes inside code spans as `\|`, as the GFM spec describes. * Encode pipes in `to_markdown` link URLs A pipe in a link URL inside a table cell ended the cell, which broke the link. Encode `|` as `%7C`.

/api

Reference documentation

/guides

In-depth tutorials