fix: Fixed issue with checklist items in Super notes not being correctly exported to HTML
This commit is contained in:
@@ -11,12 +11,13 @@ import {
|
||||
ParagraphNode,
|
||||
} from 'lexical'
|
||||
import BlocksEditorTheme from '../Lexical/Theme/Theme'
|
||||
import { BlockEditorNodes } from '../Lexical/Nodes/AllNodes'
|
||||
import { BlockEditorNodes, HTMLExportNodes } from '../Lexical/Nodes/AllNodes'
|
||||
import { MarkdownTransformers } from '../MarkdownTransformers'
|
||||
import { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html'
|
||||
|
||||
export class HeadlessSuperConverter implements SuperConverterServiceInterface {
|
||||
private editor: LexicalEditor
|
||||
private htmlExportEditor: LexicalEditor
|
||||
|
||||
constructor() {
|
||||
this.editor = createHeadlessEditor({
|
||||
@@ -26,6 +27,13 @@ export class HeadlessSuperConverter implements SuperConverterServiceInterface {
|
||||
onError: (error: Error) => console.error(error),
|
||||
nodes: [...BlockEditorNodes],
|
||||
})
|
||||
this.htmlExportEditor = createHeadlessEditor({
|
||||
namespace: 'BlocksEditor',
|
||||
theme: BlocksEditorTheme,
|
||||
editable: false,
|
||||
onError: (error: Error) => console.error(error),
|
||||
nodes: HTMLExportNodes,
|
||||
})
|
||||
}
|
||||
|
||||
isValidSuperString(superString: string): boolean {
|
||||
@@ -42,6 +50,25 @@ export class HeadlessSuperConverter implements SuperConverterServiceInterface {
|
||||
return superString
|
||||
}
|
||||
|
||||
if (toFormat === 'html') {
|
||||
this.htmlExportEditor.setEditorState(this.htmlExportEditor.parseEditorState(superString))
|
||||
|
||||
let content: string | undefined
|
||||
|
||||
this.htmlExportEditor.update(
|
||||
() => {
|
||||
content = $generateHtmlFromNodes(this.htmlExportEditor)
|
||||
},
|
||||
{ discrete: true },
|
||||
)
|
||||
|
||||
if (typeof content !== 'string') {
|
||||
throw new Error('Could not export note')
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
this.editor.setEditorState(this.editor.parseEditorState(superString))
|
||||
|
||||
let content: string | undefined
|
||||
@@ -60,9 +87,6 @@ export class HeadlessSuperConverter implements SuperConverterServiceInterface {
|
||||
content = $convertToMarkdownString(MarkdownTransformers)
|
||||
break
|
||||
}
|
||||
case 'html':
|
||||
content = $generateHtmlFromNodes(this.editor)
|
||||
break
|
||||
case 'json':
|
||||
default:
|
||||
content = superString
|
||||
|
||||
Reference in New Issue
Block a user