Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug]: deserializeMd keeps `\r` at the end of code-block lines for CRLF input, and serializeMd writes mixed line endings inside the fence

Aperta Adatta ai principianti
#5,322 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Inizia da packages/markdown/src/lib/rules/defaultRules.ts, nella regola di deserializzazione code_block, vicino a .split('\n') menzionato nel report. Confronta gli input CRLF e LF della riproduzione e controlla i test Markdown esistenti per i blocchi di codice. Il lavoro è terminato quando l’input CRLF produce lo stesso testo della riga di codice e lo stesso output serializzato dell’input LF, senza modificare il comportamento con LF.

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

Descrizione

Bug type

Behavior bug (incorrect output/state without crash)

Browser surface

No

Owner surface

Plate framework or plugin

Summary

For a fenced code block with CRLF line endings, deserializeMd keeps \r at the end of every code line except the last, and serializeMd then writes those lines with CRLF inside an LF fence.

Public reproduction URL

https://gist.github.com/venmakli/b48c1f9fe4cc9318e54515b5da0fcc74

Steps to reproduce
  1. Download the reproduction (package.json and repro.ts).
  2. Run bun install && bun repro.ts.
  3. For the CRLF input the first code_line is "const a = 1;\r", and the serialized fence contains const a = 1;\r\n between LF lines. The LF input gives clean lines.
Expected behavior

CRLF is a line ending (CommonMark spec, "Characters and lines"), so the CRLF input gives the same value as its LF version, which repro.ts prints next to it: code lines "const a = 1;" and "const b = 2;". Serialization gives the same output as for the LF version: ```js\nconst a = 1;\nconst b = 2;\n```\n.

Actual behavior

On @platejs/markdown 53.3.18 (output of repro.ts):

"```js\r\nconst a = 1;\r\nconst b = 2;\r\n```\r\n"
  value:     [{"children":[{"children":[{"text":"const a = 1;\r"}],"type":"code_line"},{"children":[{"text":"const b = 2;"}],"type":"code_line"}],"lang":"js","type":"code_block"}]
  serialize: "```js\nconst a = 1;\r\nconst b = 2;\n```\n"
"```js\nconst a = 1;\nconst b = 2;\n```\n"
  value:     [{"children":[{"children":[{"text":"const a = 1;"}],"type":"code_line"},{"children":[{"text":"const b = 2;"}],"type":"code_line"}],"lang":"js","type":"code_block"}]
  serialize: "```js\nconst a = 1;\nconst b = 2;\n```\n"

The \r is part of the code-line text in the editor value. The serialized fence mixes CRLF (inside) and LF (fence and last line).

Acceptance criteria
  • For CRLF input, no code_line text contains \r from a line ending; the value equals the value for the LF version of the same input.
  • serializeMd output for that value equals the output for the LF version: no \r inside the fence.
  • Output for LF input is unchanged.
Regression range
last-known-good: NOT_ENOUGH_INFO
first-known-bad: NOT_ENOUGH_INFO
evidence: >
  Same value and output observed on @udecode/plate-markdown 47.0.4 (with @udecode/plate 46.0.10),
  @platejs/markdown 53.1.5 and 53.3.18. The code_block rule splits `mdastNode.value` with `.split('\n')`
  (v53.3.18 packages/markdown/src/lib/rules/defaultRules.ts:296; the same split is in the 47.0.4 dist).
  git blame at v53.3.18 points to the lint commit d13624190 (PR #4732), so the split is older; the introducing commit was not identified.
Reproducibility

Always

Plate / Plite / React versions
plate: "@platejs/markdown 53.3.18, platejs 53.3.18 (mdast-util-from-markdown 2.1.0, mdast-util-to-markdown 2.2.1)"
plite: not used
plite-react: not used
react: not used
Operating system

macOS 15 (Darwin 24.6.0)

Install method

bun 1.4.4: bun install && bun repro.ts

Framework / app setup

Headless createSlateEditor with MarkdownPlugin only, no React.

Affected packages or entry points

@platejs/markdown: editor.api.markdown.deserialize / deserializeMd (code_block rule), editor.api.markdown.serialize.

Minimal code or config excerpt
import { MarkdownPlugin } from '@platejs/markdown';
import { createSlateEditor } from 'platejs';

const editor = createSlateEditor({ plugins: [MarkdownPlugin] });

for (const input of ['```js\r\nconst a = 1;\r\nconst b = 2;\r\n```\r\n', '```js\nconst a = 1;\nconst b = 2;\n```\n']) {
  const value = editor.api.markdown.deserialize(input);
  editor.tf.setValue(value);
  console.log(JSON.stringify(input));
  console.log('  value:    ', JSON.stringify(value));
  console.log('  serialize:', JSON.stringify(editor.api.markdown.serialize()));
}
Logs, screenshots, and evidence
# mdast from mdast-util-from-markdown 2.1.0 for the CRLF input: the code value keeps CRLF
"const a = 1;\r\nconst b = 2;"

# @udecode/plate-markdown 47.0.4 + @udecode/plate 46.0.10, CRLF input
[{"children":[{"children":[{"text":"const a = 1;\r"}],"type":"code_line"},{"children":[{"text":"const b = 2;"}],"type":"code_line"}],"lang":"js","type":"code_block"}]
"```js\nconst a = 1;\r\nconst b = 2;\n```\n"
Maintainer Codex context
route: N/A (headless)
local command: bun install && bun repro.ts
fixture/data: the two inputs in repro.ts
rule location: >
  v53.3.18 and main (170d73db6, 2026-10-23): packages/markdown/src/lib/rules/defaultRules.ts:296 (code_block deserialize).
  next: not checked; the code-block plugin lives in packages/platejs/src/features/code-block there.
known blocker: none
Impact and severity
  • Affected: @platejs/markdown users who deserialize Markdown files with CRLF line endings that contain fenced code blocks. Observed on Windows-style input bytes; the OS running the code does not matter.
  • Severity: data risk inside code. Code text in the editor carries a hidden \r, and the written file gets mixed line endings.
  • Frequency: always for CRLF input with a code block of two or more lines.
  • Consequence: diffs of the Markdown file show changed code lines, and copied code keeps the stray \r.
Additional information

Paragraph and blockquote text under CRLF is a separate report (lone \r and extra \ after PR #5026). This report is only about code-block lines. LF output between blocks (mdast-util-to-markdown always joins with \n) is not part of it.

Lingua principale
TypeScript
Stelle
16.6k
Fork
993
Merge medio
20h 21m
PR unite (30g)
60

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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.

Altre issue di udecode/plate

Tutte le issue di udecode/plate

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.