feat: Notes from Evernote ENEX files are now correctly imported as Super notes with attachments (#2467)

This commit is contained in:
Aman Harwara
2023-08-30 00:32:54 +05:30
committed by GitHub
parent 631972ca9c
commit 600afa5382
11 changed files with 730 additions and 93 deletions

View File

@@ -88,41 +88,58 @@ export class HeadlessSuperConverter implements SuperConverterServiceInterface {
return otherFormatString
}
this.editor.update(
() => {
$getRoot().clear()
},
{
discrete: true,
},
)
let didThrow = false
if (fromFormat === 'html') {
this.editor.update(
() => {
const root = $getRoot()
root.clear()
try {
const parser = new DOMParser()
const dom = parser.parseFromString(otherFormatString, 'text/html')
const generatedNodes = $generateNodesFromDOM(this.editor, dom)
const nodesToInsert: LexicalNode[] = []
generatedNodes.forEach((node) => {
const type = node.getType()
const parser = new DOMParser()
const dom = parser.parseFromString(otherFormatString, 'text/html')
const generatedNodes = $generateNodesFromDOM(this.editor, dom)
const nodesToInsert: LexicalNode[] = []
generatedNodes.forEach((node) => {
const type = node.getType()
// Wrap text & link nodes with paragraph since they can't
// be top-level nodes in Super
if (type === 'text' || type === 'link' || type === 'unencrypted-image' || type === 'inline-file') {
const paragraphNode = $createParagraphNode()
paragraphNode.append(node)
nodesToInsert.push(paragraphNode)
return
} else {
nodesToInsert.push(node)
}
// Wrap text & link nodes with paragraph since they can't
// be top-level nodes in Super
if (type === 'text' || type === 'link') {
const paragraphNode = $createParagraphNode()
paragraphNode.append(node)
nodesToInsert.push(paragraphNode)
return
} else {
nodesToInsert.push(node)
}
nodesToInsert.push($createParagraphNode())
})
$getRoot().selectEnd()
$insertNodes(nodesToInsert.concat($createParagraphNode()))
nodesToInsert.push($createParagraphNode())
})
$getRoot().selectEnd()
$insertNodes(nodesToInsert.concat($createParagraphNode()))
} catch (error) {
console.error(error)
didThrow = true
}
},
{ discrete: true },
)
} else {
this.editor.update(
() => {
$convertFromMarkdownString(otherFormatString, MarkdownTransformers)
try {
$convertFromMarkdownString(otherFormatString, MarkdownTransformers)
} catch (error) {
console.error(error)
didThrow = true
}
},
{
discrete: true,
@@ -130,6 +147,10 @@ export class HeadlessSuperConverter implements SuperConverterServiceInterface {
)
}
if (didThrow) {
throw new Error('Could not import note')
}
return JSON.stringify(this.editor.getEditorState())
}
}