Skip to content

RFC: Allow $generateHtmlFromNodes to not export classes #6968

Open
@ivailop7

Description

@ivailop7

Lexical: 0.21

export function $generateHtmlFromNodes(
editor: LexicalEditor,
selection?: BaseSelection | null,
): string {
if (
typeof document === 'undefined' ||
(typeof window === 'undefined' && typeof global.window === 'undefined')
) {
throw new Error(
'To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.',
);
}
const container = document.createElement('div');
const root = $getRoot();
const topLevelChildren = root.getChildren();
for (let i = 0; i < topLevelChildren.length; i++) {
const topLevelNode = topLevelChildren[i];
$appendNodesToHTML(editor, topLevelNode, container, selection);
}
return container.innerHTML;
}

The currently exported HTML would contain theme classes, which in many cases would mean something only to the current application that provides them in its theme configuration and add no meaningful value to any external copy/paste use case. Since the classes would be reapplied on editor state reparsing. It makes sense to allow skipping the export of the 'class' attribute when generating the HTML. It also has benefit in terms of smaller HTML footprint for storage, for those that store the HTML instead of the EditorState.

Edit: I do think, we should keep the 'style' attribute or make it extra configurable and not couple 'class' and 'style' together.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement over existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions