Skip to content

🐛 Bug: transformMarkdownLinks regex fails on implicit and collapsed reference links #2265

@h30s

Description

@h30s

Describe the bug

The custom markdown pre-processor transformMarkdownLinks in lib/markdownUtils.ts (used by StyledMarkdown.tsx) uses a regular expression that breaks standard Markdown reference links. Specifically, it fails to parse implicit reference links (like [text][]) and completely ignores collapsed reference links ([text]).
This negatively impacts the authoring experience because contributors writing documentation have to redundantly type out their reference links (e.g., [JSON Schema][JSON Schema]) just to appease the custom parser, deviating from standard Markdown spec behavior.

Steps To Reproduce

  1. Author or preview any markdown file in the website that uses StyledMarkdown.tsx.
  2. Add a standard empty bracket reference link: Here is a [link][] and define it below: [link]: https://example.com
  3. Add a collapsed reference link: Here is a [link] and define it below.
  4. Render the page.
  5. See error: The links are not converted to anchor tags; they render as raw text.

Expected Behavior

Both [link][] and [link] should be correctly parsed and converted into standard inline markdown links [link](https://example.com). The regex should fallback to matching the primary text if the secondary ID block is empty or missing.

Screenshots

No response

Device Information [optional]

- OS:
- Browser:
- version:

Are you working on this issue?

Yes

Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)

No

Metadata

Metadata

Assignees

Labels

Status: TriageThis is the initial status for an issue that requires triage.🐛 BugIndicates that the issue is a bug or defect.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions