Skip to content

Table copy drops line breaks from cells containing <br> #553

Description

@hjlarry

Bug Description

When copying a rendered Markdown table as Markdown, CSV, or TSV, line breaks inside table cells are lost from the text/plain clipboard representation.

The issue appears to be caused by extractTableDataFromElement(), which uses cell.textContent?.trim().

For a rendered cell such as <td>Paragraph one.<br>Paragraph two.</td>, textContent returns Paragraph one.Paragraph two.. The <br> is therefore lost before the table is serialized.

The HTML clipboard representation still contains the <br>, so rich-text paste and plain-text paste produce inconsistent results.

Steps to Reproduce

  1. Render the following Markdown with Streamdown:

    | Name | Description |
    | --- | --- |
    | Example | Paragraph one.<br>Paragraph two. |
  2. Open the copy dropdown on the rendered table.

  3. Select CSV or TSV.

  4. Paste the copied content into a plain-text editor.

The problem can also be observed by reading the text/plain clipboard representation, for example with pbpaste on macOS.

Minimal example:

import { Streamdown } from "streamdown";
import "streamdown/styles.css";

const markdown = `
| Name | Description |
| --- | --- |
| Example | Paragraph one.<br>Paragraph two. |
`;

export default function App() {
  return <Streamdown>{markdown}</Streamdown>;
}

Expected Behavior

Line breaks in table cells should be preserved when generating the plain-text Markdown, CSV, or TSV representation.

For CSV, the multiline field should contain a real newline and be quoted:

Example,"Paragraph one.
Paragraph two."

For TSV or Markdown, the line break should also be represented without merging the two paragraphs into one continuous string.

Actual Behavior

The line break is removed completely:

Example,Paragraph one.Paragraph two.

The two paragraphs are concatenated without a newline or even a separating space.

Pasting the same clipboard content into an application that reads the text/html representation may preserve the line break because the HTML still contains <br>. The problem affects the generated text/plain representation.

Code Sample

Streamdown Version

2.5.0

React Version

19.2.7

Node.js Version

No response

Browser(s)

No response

Operating System

None

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions