Add a configurable Markdown link serialization policy

未關閉
#3,035 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
68/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
react, typescript
領域
frontend

研究方向

Start at the public blocksToMarkdownLossy entry point and trace into the lower-level Markdown exporter’s link serialization. Verify how URL-only links and separately labelled links are currently emitted. Done means an opt-in explicit style is supported, auto preserves existing output, and both link cases have coverage.

由索引模型根據 Issue 內容生成。

描述

What’s broken?

The Markdown exporter does not provide a public option to control how links are serialized.

When a URL-only link is created in BlockNote, blocksToMarkdownLossy may serialize it as a bare URL:

https://example.com

This is valid in GFM, but it loses the explicit distinction between ordinary text and a Markdown link. It also makes it difficult for applications to enforce a consistent Markdown export policy.

What did you expect to happen?

Applications should be able to choose whether links are serialized as:

https://example.com

or explicitly as:

[https://example.com](https://example.com)

For links with a separate label, the explicit format should remain:

[Documentation](https://example.com)

The default behavior should remain unchanged for backward compatibility.

Steps to reproduce
  1. Create a BlockNote editor.
  2. Insert a link where the displayed text is the same as the URL.
  3. Export the document with blocksToMarkdownLossy.
  4. Observe that the result may contain a bare URL instead of explicit Markdown link syntax.

Example:

const markdown = editor.blocksToMarkdownLossy(editor.document);
console.log(markdown);

Observed output:

https://example.com

Desired opt-in output:

[https://example.com](https://example.com)
BlockNote version

v0.54.0

Environment

React application, macOS

Proposed API

One possible API would be an export option:

editor.blocksToMarkdownLossy(editor.document, {
  linkStyle: "explicit",
});

Possible values:

type MarkdownLinkStyle = "auto" | "explicit";

Where:

  • "auto" preserves the current behavior.
  • "explicit" always emits [label](url) for links.
  • Links with different labels continue to emit [label](url).

The option could be exposed through the lower-level Markdown exporter API as well.

Additional context

We initially implemented an application-level HTML-to-Markdown serializer only to change this link behavior. However, that requires duplicating BlockNote’s complete Markdown serialization logic and creates compatibility and maintenance risks when BlockNote changes its exporter.

A public link serialization option or hook would allow applications to customize this behavior without forking the whole serializer.

Contribution

I’d be interested in contributing a fix for this issue.

主要語言
TypeScript
星號
10.2k
分支
772
平均合併
3 天 11 小時
30 天內合併 PR
17

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TypeCellOS/BlockNote 的其他 Issue

查看 TypeCellOS/BlockNote 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。