Skip to content

[lexical-markdown] Bug Fix: Drop the closing # sequence of an ATX heading on import - #9532

Open
kevin9327 wants to merge 1 commit into
meta:mainfrom
kevin9327:fix/markdown-heading-closing-sequence
Open

kevin9327 wants to merge 1 commit into
meta:mainfrom
kevin9327:fix/markdown-heading-closing-sequence

Conversation

@kevin9327

@kevin9327 kevin9327 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

In CommonMark an ATX heading can end with a closing sequence of # characters. That sequence is not part of the heading text (example 71):

## Hello world ##

renders as <h2>Hello world</h2>. $convertFromMarkdownString keeps the #s as text instead. So in the editor the heading reads "Hello world ##", with the closing #s shown as part of the title.

On import, HEADING.replace now strips a trailing closing sequence from the heading's text: one or more #, optionally followed by spaces or tabs. As the spec requires, the sequence must be preceded by a space or tab, so # Hello C# keeps its #. The typing shortcut (isImport === false) is unchanged.

Test plan

New cases in LexicalMarkdown.test.ts:

  • ## Hello world ## imports as an h2 reading Hello world.
  • # Hello world ##### (longer sequence plus trailing spaces) imports as an h1 reading Hello world.
  • # Hello C# still imports as Hello C# and round-trips.

Before

× can import "## Hello world ##"
× can import "# Hello world #####   "
Tests  2 failed | 812 passed (814)

After

pnpm exec vitest --project unit --no-watch packages/lexical-markdown

Tests  814 passed (814)

Prettier, ESLint and tsc --noEmit are clean.

AI-assisted: I directed the investigation and reviewed and verified the change myself.

@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Oct 29, 2026 9:34pm UTC
lexical-playground Ready Ready Preview Oct 29, 2026 9:34pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9532

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9532

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9532

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9532

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9532

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9532

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9532

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9532

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9532

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9532

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9532

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9532

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9532

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9532

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9532

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9532

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9532

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9532

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9532

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9532

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9532

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9532

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9532

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9532

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9532

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9532

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9532

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9532

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9532

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9532

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9532

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9532

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9532

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9532

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9532

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9532

commit: 048d6f9

This branch was successfully deployed

2 active deployments
Preview – lexical — 048d6f95 Deployed Oct 29, 2026 by vercel[bot]
Preview – lexical-playground — 048d6f95 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant