Skip to content

[lexical] Feature: Add html.isInlineDomNode API for custom inline DOM elements#8477

Closed
abhishekvishwakarma007 wants to merge 1 commit into
facebook:mainfrom
abhishekvishwakarma007:feat/custom-inline-dom-node-api
Closed

[lexical] Feature: Add html.isInlineDomNode API for custom inline DOM elements#8477
abhishekvishwakarma007 wants to merge 1 commit into
facebook:mainfrom
abhishekvishwakarma007:feat/custom-inline-dom-node-api

Conversation

@abhishekvishwakarma007

Copy link
Copy Markdown
Contributor

Summary

Closes #8391

When importing HTML into Lexical, whitespace is only preserved around known native HTML inline elements (like <span>, <b>, <a>) or elements with explicit display: inline CSS. Custom elements like <tooltip> or <mention> are not recognized as inline, causing adjacent whitespace to be stripped during import.

This PR adds an isInlineDomNode option to HTMLConfig that accepts a predicate function, allowing users to declare which custom DOM elements should be treated as inline during HTML import.

Usage

createEditor({
  html: {
    isInlineDomNode: (node) => node.nodeName.toLowerCase() === 'tooltip',
  },
});

Changes

  • packages/lexical/src/LexicalEditor.ts — Added isInlineDomNode to HTMLConfig type
  • packages/lexical/src/LexicalUtils.ts — Modified isInlineDomNode() to check the active editor's custom predicate as a fallback when built-in checks fail
  • packages/lexical/flow/Lexical.js.flow — Flow type parity
  • packages/lexical-extension/src/LexicalBuilder.ts — Fixed LexicalBuilder to forward isInlineDomNode config through the Extension system (it was only forwarding import and export)
  • packages/lexical-html/src/__tests__/unit/LexicalHtml.test.ts — 4 tests covering: default behavior (whitespace stripped), fix working (whitespace preserved), multiple custom elements, and native elements unaffected

Before (bug)

<p>Hello <tooltip>world</tooltip> foo</p>

Produces: "Helloworldfoo" — spaces around <tooltip> are stripped

After (fix)

With isInlineDomNode configured, produces: "Hello world foo" — spaces preserved

Test plan

  • All 3042 existing unit tests pass (0 regressions)
  • 4 new tests added and passing
  • TypeScript check passes
  • ESLint/Prettier pass (pre-commit hooks)
  • Flow types updated

…OM elements (facebook#8391)

When importing HTML, Lexical only preserves whitespace around known native inline elements (span, b, a, etc.) or elements with explicit `display: inline` style. Custom elements like `<tooltip>` or `<mention>` are treated as block-level, causing adjacent whitespace to be stripped.

This adds an `isInlineDomNode` option to `HTMLConfig` that accepts a predicate function, allowing users to declare which custom DOM elements should be treated as inline during HTML import.

Usage:
```js
createEditor({
  html: {
    isInlineDomNode: (node) => node.nodeName.toLowerCase() === 'tooltip',
  },
});
```
@vercel

vercel Bot commented May 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 7, 2026 2:56pm
lexical-playground Ready Ready Preview, Comment May 7, 2026 2:56pm

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 May 7, 2026
@etrepum

etrepum commented May 7, 2026

Copy link
Copy Markdown
Collaborator

I'm not sure this is a good idea, the importDOM machinery is really due for an overhaul, not more duct tape.

@levensta

levensta commented May 7, 2026

Copy link
Copy Markdown
Contributor

I'm not sure this is a good idea, the importDOM machinery is really due for an overhaul, not more duct tape.

Although this is a patch to the current importDOM, there are tests here that will help take into account the current feature for the future redesigned HTML import API

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.

Feature: Add API for checking custom inline DOM element

3 participants