Repository navigation
Description
Versions
- htmd 0.6.0 (affected)
- htmd 0.5.5 (previous behavior)
Minimal input
let md = htmd::convert("<code><a href=\"https://example.com\">first\nsecond</a></code>").unwrap();Actual output (0.6.0)
`[first second](https://example.com)`
Output of 0.5.5
`[first
second](https://example.com)`
(that is, "first\nsecond", with a bare line ending inside the code span.)
Expected
A code span does not decode character references, so in 0.6.0's output the reader sees the literal text . CommonMark 0.31.2, code spans: "First, line endings are converted to spaces." So the 0.5.5 output renders as [first second](https://example.com) in a code span, and the closest faithful 0.6.0 output is the same line ending, or, equivalently, a single space:
`[first second](https://example.com)`
A backslash-escaped line break would not be right here: backslash escapes and hard line breaks are not recognized inside code spans, so \ would render literally.
Note that 0.6.0 already does this for text directly inside <code> (<code>first\nsecond</code> gives `first second`, via element_handler/code.rs, "writing that space is what the span meant anyway"). The link inside is the case it misses.
Trigger conditions
Observed with htmd::convert and default options:
| Input | 0.5.5 | 0.6.0 |
|---|---|---|
<code><a href="https://example.com">first\nsecond</a></code> |
`[first\nsecond](https://example.com)` |
`[first second](https://example.com)` |
<pre><code><a href="https://example.com">first\nsecond</a></code></pre> |
fenced block, [first\nsecond](https://example.com) |
fenced block, [first second](https://example.com) |
<code>first\nsecond</code> |
`first\nsecond` |
`first second` |
<a href="https://example.com">first\nsecond</a> |
[first second](https://example.com) |
[first second](https://example.com) |
<a href="https://example.com"><code>first\nsecond</code></a> |
[`first\nsecond`](https://example.com) |
[`first second`](https://example.com) |
<code><em>first\nsecond</em></code> |
`*first\nsecond*` |
`*first second*` |
So it needs an <a href> whose text holds a line ending, nested inside <code> (inline, or inside <pre><code>, where the entity is also literal text). Without the href, or with the link outside the code, it does not occur. (\n above is a real line feed in the input.)
Source
In 0.6.0 the anchor handler encodes every line ending in its content unconditionally, with no regard for the context it sits in:
src/element_handler/anchor.rs:167:let content = encode_line_endings(&content);src/util/escape.rs:219-226:encode_line_endingsmaps\rto and\nto .
The encoding is right for ordinary link text, where a reference decodes back to the line ending. Inside a code span or code block it is not decoded, so the entity shows. The code handler's own line-ending handling (src/element_handler/code.rs:156-176) runs on the code element's content, which by then holds the already-encoded text, so it never sees a line ending to replace.
A possible fix is to skip the encoding when the context is code (the handler already receives element.context), or to leave the line ending for the code handler to turn into a space.
Reproduction
Two binary crates, identical main.rs, differing only in htmd = "=0.5.5" versus htmd = "=0.6.0":
fn main() {
let html = "<code><a href=\"https://example.com\">first\nsecond</a></code>";
println!("{:?}", htmd::convert(html).unwrap());
}0.5.5 prints "first\nsecond"; 0.6.0 prints "first
second".
Activity
letmutex commentedon Nov 24, 2026
Thanks for reporting! Fixed in https://github.com/letmutex/htmd/releases/tag/v0.6.1