我是新手。我想从lexical/react
编辑器中得到降价值。我在我的项目中使用RichTextPlugin
。但是我不能得到降价值。我怎样才能得到降价值呢?这是我的代码;
function Placeholder() {
return <div className="editor-placeholder">Yazmaya başlayabilirsiniz...</div>;
}
const editorConfig = {
// The editor theme
namespace: "ArticleEditor",
theme: ExampleTheme,
// Handling of errors during update
onError(error) {
throw error;
},
// Any custom nodes go here
nodes: [
HeadingNode,
ListNode,
ListItemNode,
QuoteNode,
CodeNode,
CodeHighlightNode,
TableNode,
TableCellNode,
TableRowNode,
AutoLinkNode,
LinkNode
]
};
export default function Editor() {
const onChange = (editorState) => {
editorState.read(() => {
// Read the contents of the EditorState here.
const root = $getRoot();
const selection = $getSelection();
});
}
return (
<LexicalComposer initialConfig={editorConfig}>
<div className="editor-container border rounded-2">
<div className="overflow-auto bg-100 position-relative">
<ToolbarPlugin/>
</div>
<div className="editor-inner border-top border-dashed">
<RichTextPlugin
contentEditable={<ContentEditable className="editor-input"/>}
placeholder={<Placeholder/>}
ErrorBoundary={LexicalErrorBoundary}
/>
<OnChangePlugin onChange={onChange}/>
<HistoryPlugin/>
{/*<TreeViewPlugin/>*/}
{/*<AutoFocusPlugin/>*/}
<CodeHighlightPlugin/>
<ListPlugin/>
<LinkPlugin/>
<AutoLinkPlugin/>
<TablePlugin/>
<ListMaxIndentLevelPlugin maxDepth={7}/>
<MarkdownShortcutPlugin transformers={TRANSFORMERS}/>
</div>
</div>
</LexicalComposer>
);
}
在onChange()
函数中使用$getRoot()
可以得到plain text
形式的值。
1条答案
按热度按时间myzjeezk1#
根据词法文档,你可以使用markdown包将编辑器的节点转换为markdown:https://lexical.dev/docs/packages/lexical-markdown