Skip to content

Pure mode loses bare pre blocks and literal Markdown text #168

Done

Description

@lemone112

Tested the registry release htmd = "=0.6.1" (GitHub release published 2026-11-24 01:44:42 UTC, tag commit f8284c82493920ac6d2ab2e553fefd1731f00c76). The result is identical with the default ego-tree backend and default-features = false, features = ["rcdom"].

A bare pre is returned as ordinary Markdown. Its literal content can consequently become a heading or a fence instead of remaining code. A pre nested under an inline ancestor also loses the preformatted block entirely. Highlighted pre > code correctly retains its line breaks in this release, so the remaining problem is specifically the bare pre contract and its surrounding context.

Minimal reproducer

[package]
name = "htmd-pre-repro"
version = "0.0.0"
edition = "2024"

[dependencies]
htmd = "=0.6.1"
fn main() {
    for input in [
        "<main><em><a</em><span><PRe\n>></span></main>",
        "<main><em><pre>></pre></em></main>",
        "<pre><span># comment</span>\n<span>echo </span><span>one</span>\n\n\n<span>  next</span>\n</pre>",
        "<pre>```\n# title\n~~~\n</pre>",
    ] {
        println!("{:?}", htmd::convert(input).unwrap());
    }
}

Actual output:

"*>*"
"*>*"
"# comment\necho one\n\n\n  next"
"\\```\n# title\n~~~"

The first input contains exactly 44 UTF-8 bytes, including the LF after PRe. HTML5 parsing produces main → em → a< [em=""] → span → pre → Text(">"). The second input reproduces the same failure without the malformed anchor token. The third and fourth are valid bare-pre examples.

Semantic evidence

I rendered each result with pulldown-cmark = "=0.13.6", Options::all(), parsed the resulting HTML with dom_query = "=0.28.0", and compared the text of outermost pre nodes. Only a missing final LF is normalized on either side.

Case Original pre text Pre text after Markdown → HTML
44-byte case / direct em-pre [">\n"] []
highlighted bare pre ["# comment\necho one\n\n\n next\n"] []
literal bare pre markers ["```\n# title\n~~~\n"] ["\n"]

For comparison, the same highlighted content under pre > code yields a fenced block and preserves text and blank lines. Faithful mode preserves the tested pre text as HTML. This draft concerns the default Pure mode; switching the whole consumer to Faithful would change its output contract.

Expected behavior: preserve bare pre text as a code block, including literal Markdown markers, indentation, and blank lines; do not turn the block into prose when an outer inline wrapper is present. Exact output spelling can differ as long as rendering restores the original preformatted text.

Relevant current implementation

  • pre_handler: Pure mode walks literal children and calls frame_as_block; bare text receives no code fence.
  • emphasis_handler: children are evaluated with ContextKind::Inline.
  • translation_approach.md: documents Pure/Faithful tradeoffs. If losing bare-pre semantics is intentional, please clarify that support boundary; currently pre > code and bare pre have materially different behavior for the same literal program text.
  • Release v0.6.1.

Activity

  1. letmutex commented on Nov 24, 2026

    @letmutex
    Owner

    Possibly related to #164 .

    I would recommend using custom handlers for bare pre to code block conversions, since pre tag itself doesn't compile to a code block, doing so could lead to semantic mismatches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions