-
Notifications
You must be signed in to change notification settings - Fork 2.1k
RFC: Allow $generateHtmlFromNodes to not export classes #6968
Description
Lexical: 0.21
lexical/packages/lexical-html/src/index.ts
Lines 67 to 90 in ddd0903
| 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.