Skip to content

fix(markdown): avoid autolink angle brackets when copying plain URL l…#2661

Open
Ovgodd wants to merge 2 commits intoTypeCellOS:mainfrom
Ovgodd:fix/markdown-copy-link-autolink-brackets
Open

fix(markdown): avoid autolink angle brackets when copying plain URL l…#2661
Ovgodd wants to merge 2 commits intoTypeCellOS:mainfrom
Ovgodd:fix/markdown-copy-link-autolink-brackets

Conversation

@Ovgodd
Copy link
Copy Markdown
Contributor

@Ovgodd Ovgodd commented Apr 20, 2026

Purpose

Fix broken links when copying a URL from a BlockNote document and pasting it
into another input (link toolbar).

When copying content from the editor, BlockNote serializes links to
text/plain using Markdown. Plain URL links (where text = URL) were
serialized as Markdown autolinks (<https://example.com>), causing the angle
brackets to be included wherever the text was pasted, resulting in invalid
hrefs.

Proposal

  • Add a custom link handler in remarkStringify inside
    cleanHTMLToMarkdown to output plain URLs instead of Markdown autolink
    format when the link text equals the URL
  • When the link has a distinct label, the standard Markdown format
    [label](url) is preserved

Summary by CodeRabbit

  • Bug Fixes
    • Improved Markdown export link handling to avoid autolink-style rendering when link text equals the URL.
    • Descriptive links continue to export as standard Markdown (text) for readability.
    • URLs are now escaped when needed to ensure links render correctly in parentheses and other contexts.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

@Ovgodd is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad239a21-7744-4e4e-9a5e-384dfc9e3d3e

📥 Commits

Reviewing files that changed from the base of the PR and between 9261548 and c0daf5b.

📒 Files selected for processing (1)
  • packages/core/src/api/exporters/markdown/markdownExporter.ts

📝 Walkthrough

Walkthrough

Updated the markdown exporter's remark-stringify configuration to add a custom link handler that emits a plain URL when link text is missing or equals the raw URL; otherwise it emits a Markdown link [text](escaped-url) using state.safe for URL escaping.

Changes

Cohort / File(s) Summary
Markdown Exporter Link Handler
packages/core/src/api/exporters/markdown/markdownExporter.ts
Added a custom link handler to the remark stringify config. It conditionally outputs plain node.url when children are missing or match the raw URL, otherwise emits [children](safe-url) with state.safe used to escape the URL.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~13 minutes

Poem

🐰 I nibble links with careful cheer,
If text is same, the URL stays clear.
Else I tuck it in brackets neat,
With parentheses to make it complete.
Hop—markdown tidy, tasty, and dear! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely describes the main fix: avoiding autolink angle brackets when copying plain URLs, which aligns with the primary change in the markdown exporter.
Description check ✅ Passed The description includes Purpose and Proposal sections with clear explanation of the problem and solution, but is missing several template sections like Rationale, Changes, Impact, Testing, Checklist, and Additional Notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix/markdown-copy-link-autolink-brackets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/api/exporters/markdown/markdownExporter.ts`:
- Around line 39-49: The labeled-link branch in the markdown link renderer
(link: (node, _parent, state) => { ... }) interpolates node.url raw, producing
invalid Markdown for URLs with spaces or special chars; update it to use
state.safe(...) to escape the destination when constructing `[label](dest)` and
ensure you pass the position-aware info parameter into state.containerPhrasing
instead of the hardcoded now/column/offset object so the label rendering
receives correct context; specifically, call state.containerPhrasing(node, {
before: "[", after: "]", lineShift: 0, info: state.info }) (or equivalent to
supply the info) and wrap the escaped destination via state.safe(state.encode ?
state.encode(node.url) : node.url, { before: "(", after: ")" }) or the
renderer's destination-aware safe variant to produce a correctly escaped link
destination.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90d7602b-e767-4062-938f-2fbeb967e6c0

📥 Commits

Reviewing files that changed from the base of the PR and between 050ec30 and 9261548.

📒 Files selected for processing (1)
  • packages/core/src/api/exporters/markdown/markdownExporter.ts

Comment thread packages/core/src/api/exporters/markdown/markdownExporter.ts Outdated
nperez0111 added a commit that referenced this pull request Apr 21, 2026
Port upstream #2661 to the custom HTML→markdown
serializer: when an anchor's label matches its href (or is empty),
output the plain URL instead of `[url](url)`, so pasting the result
into another input produces a valid link. Also escape `\`, `(`, `)` in
link destinations so URLs containing parens don't prematurely close
the `(dest)` target.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant