Skip to content

[Bug]: GitHub alert trim() removes trailing whitespace, gluing inline elements #83

@PtitBreton3531

Description

@PtitBreton3531

Package

markdown-confluence-sync

What happened?

Description

When a GitHub alert callout (e.g. > [!NOTE]) contains inline formatting (**bold**, *italic*, links, etc.) on the line right after the alert marker, the trailing whitespace before the inline element is stripped at render time. The result in Confluence is text glued to the next inline element (e.g. text**bold** rendered as text<strong>bold</strong> without the separating space).

Reproduction

Markdown source:

> [!NOTE]
> This is a callout with **bold text** inside.

After sync, the Confluence page renders this as:

This is a callout withbold text inside.

(no space between "with" and the bold word)

Expected behavior

The space between the previous word and the inline element should be preserved. The render should be:

This is a callout with bold text inside.

Actual behavior

The leading text node inside the callout is .trim()-ed, removing the trailing space that should sit between the text and the next inline element.

Cause

In components/markdown-confluence-sync/src/lib/confluence/transformer/support/rehype/rehype-replace-github-alerts.ts:

const remainingText = text.substring(alertMatch[0].length).trim();

.trim() strips both leading AND trailing whitespace. It should only strip the leading whitespace (which separates the alert marker from the actual content), not the trailing one (which separates the text from the next sibling element).

Suggested fix

Replace .trim() with a leading-only trim:

const remainingText = text.substring(alertMatch[0].length).replace(/^\s+/, '');

Workaround

Insert a blank > line between the alert marker and the content:

> [!NOTE]
>
> This is a callout with **bold text** inside.

This produces two paragraphs in the blockquote — the first one only containing the alert marker (which gets safely trimmed), the second one preserving the inline formatting untouched.

Environment

  • @telefonica/markdown-confluence-sync v2.4.0
  • Node 20+
  • Mode: tree

Version

2.x

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions