-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d9793f
commit 991cdfd
Showing
14 changed files
with
136 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { SlateElement, YooEditor, YooptaBlockData, YooptaContentValue } from '@yoopta/editor'; | ||
|
||
export function serialize(editor: YooEditor, blocksData: YooptaBlockData[]) { | ||
const blocks = blocksData.sort((a, b) => (a.meta.order > b.meta.order ? 1 : -1)); | ||
|
||
const markdown = blocks.map((blockData) => { | ||
const plugin = editor.plugins[blockData.type]; | ||
|
||
if (plugin) { | ||
const element = blockData.value[0] as SlateElement; | ||
|
||
if (plugin.parsers?.markdown?.serialize) { | ||
const serialized = plugin.parsers.markdown.serialize( | ||
element, | ||
element.children.map((child) => child.text).join(''), | ||
); | ||
if (serialized) return serialized; | ||
} | ||
} | ||
|
||
return ''; | ||
}); | ||
|
||
return markdown.join('\n'); | ||
} | ||
|
||
export function getMarkdown(editor: YooEditor, content: YooptaContentValue) { | ||
const selectedBlocks = Object.values(content); | ||
return serialize(editor, selectedBlocks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { YooEditor, YooptaContentValue } from '@yoopta/editor'; | ||
import { getHTML } from './getHTML'; | ||
|
||
export function getPlainText(editor: YooEditor, content: YooptaContentValue) { | ||
const htmlString = getHTML(editor, content); | ||
|
||
const div = document.createElement('div'); | ||
div.innerHTML = htmlString; | ||
return div.innerText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters