TypeCellOS / TypeCellOS/BlockNote

Add a configurable Markdown link serialization policy

Aperta
#3,035 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
10.2k
Fork
772
Merge medio
3g 11h
PR unite (30g)
17

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react, typescript
Ambito
frontend
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
68/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.