@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
84 lines (81 loc) • 2.78 kB
JavaScript
import { IS_BOLD, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE } from 'lexical';
import { INodeHelper } from "../../../editor-kernel/inode/helper";
export function registerMDReader(markdownService) {
markdownService.registerMarkdownReader('blockquote', function (node, children) {
return INodeHelper.createElementNode('quote', {
children: children,
direction: 'ltr',
format: '',
indent: 0,
version: 1
});
});
// strong italic del
markdownService.registerMarkdownReader('strong', function (node, children) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_BOLD;
}
return child;
});
});
// strong italic del
markdownService.registerMarkdownReader('emphasis', function (node, children) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_ITALIC;
}
return child;
});
});
// strong italic del
markdownService.registerMarkdownReader('delete', function (node, children) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_STRIKETHROUGH;
}
return child;
});
});
markdownService.registerMarkdownReader('subscript', function (node, children) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_SUBSCRIPT;
}
return child;
});
});
markdownService.registerMarkdownReader('superscript', function (node, children) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_SUPERSCRIPT;
}
return child;
});
});
markdownService.registerMarkdownReader('html', function (node, children) {
if (['<ins>', '<u>'].includes(node.value.toLocaleLowerCase())) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_UNDERLINE;
}
return child;
});
} else if (['<em>'].includes(node.value.toLocaleLowerCase())) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_ITALIC;
}
return child;
});
} else if (['<strong>'].includes(node.value.toLocaleLowerCase())) {
return children.map(function (child) {
if (INodeHelper.isTextNode(child)) {
child.format = (child.format || 0) | IS_BOLD;
}
return child;
});
}
return false;
});
}