Skip to content

Soft Markdown line breaks render as hard line breaks on native #541

Description

@sgilroy

Describe the bug

EnrichedMarkdownText renders ordinary Markdown soft breaks as visual line breaks on native platforms. This makes wrapped Markdown content display differently from typical CommonMark/GFM web renderers.

To Reproduce

  1. Render this content with EnrichedMarkdownText:

    Let's start simple: keep taking your medications as prescribed, and we'll begin tracking your
    blood sugar and blood pressure so we can see how you're really doing.
  2. Observe the rendered text on iOS or Android.

  3. A visible line break appears after your.

Expected behavior

A single newline within a paragraph is a Markdown soft break and should render as whitespace:

…we'll begin tracking your blood sugar and blood pressure…

Explicit hard breaks—two trailing spaces or a trailing backslash before the newline—should continue to render as visual line breaks.

Screenshots

Not applicable; the reproduction is visible from the supplied Markdown snippet.

Device (please complete the following information):

  • Device: Reproduced in app; exact device model can be provided if needed
  • OS: iOS / Android
  • Version: react-native-enriched-markdown@0.7.4

Additional context

The shared C++ parser currently maps both MD_TEXT_SOFTBR and MD_TEXT_BR to NodeType::LineBreak:

if (type == MD_TEXT_SOFTBR || type == MD_TEXT_BR) {
  auto brNode = std::make_shared<MarkdownASTNode>(NodeType::LineBreak);
  impl->addInlineNode(brNode);
  return 0;
}

Suggested behavior:

if (type == MD_TEXT_SOFTBR) {
  impl->currentText.append(" ");
  return 0;
}

if (type == MD_TEXT_BR) {
  auto brNode = std::make_shared<MarkdownASTNode>(NodeType::LineBreak);
  impl->addInlineNode(brNode);
  return 0;
}

Because this parser is shared native code, the issue affects both iOS and Android.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions