Skip to content

A line ending with two spaces does not produce a hard line break #42

Open

Description

@kungfutse

@tanstack/markdown 1.2.0 does not produce a hard line break when a line ends with two or more spaces. CommonMark requires one, and react-markdown 9.1.0 renders it. Only the backslash form (\ before the newline) produces a break node.

Reproduction

import { renderToStaticMarkup } from "react-dom/server";
import { Markdown } from "@tanstack/markdown/react";

renderToStaticMarkup(<Markdown>{"a  \nb"}</Markdown>);
// actual:   <p>a\nb</p>
// expected: <p>a<br/>\nb</p>

Tested with React 19 renderToStaticMarkup and no options. · marks a space in the input column.

Input @tanstack/markdown 1.2.0 react-markdown 9.1.0
a··\nb (2 trailing spaces) <p>a\nb</p> <p>a<br/>\nb</p>
a···\nb (3 trailing spaces) <p>a\nb</p> <p>a<br/>\nb</p>
a··\r\nb (CRLF) <p>a\nb</p> <p>a<br/>\nb</p>
a\ + newline + b (backslash) <p>a<br/>b</p> <p>a<br/>\nb</p>
a\nb (plain newline) <p>a\nb</p> <p>a\nb</p>
  • Two or more trailing spaces before a newline are never turned into a hard break. This holds for LF and CRLF line endings.
  • The backslash hard break works, and a plain newline correctly stays a soft break.
  • CommonMark (spec: hard line breaks) says two or more spaces at the end of a line, with more text after it in the same paragraph, are a hard line break.

I only checked @tanstack/markdown/react, not @tanstack/markdown/html, and only version 1.2.0.

Edit: And yes, I understand that full CommonMark compliance is not in the project scope, but this seems like a relatively easy addition

Activity

  1. changed the title [-]A line ending with to spaces does not produce a linebreak[/-] [+]A line ending with two spaces does not produce a linebreak[/+] on Nov 18, 2026
  2. changed the title [-]A line ending with two spaces does not produce a linebreak[/-] [+]A line ending with two spaces does not produce a hard line break[/+] on Nov 18, 2026
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