我想从 Lexical Rich Editor 中的 editorState 生成 HTML 格式,我可以使用 editorState 进行选择,什么最好保存到数据库、HTML 或某种 JSON 格式中?
我想在编辑器之外显示这个 HTML。这是一些代码示例
const onChange = (editorState) => {
const editorStateTextString = editorState.read(() => {
const selection = $getSelection();
console.log(selection);
return $getRoot().getTextContent();
});
// TODO: saving text only at the moment
if (changeHandler) {
changeHandler(editorStateTextString);
}
};
<LexicalComposer initialConfig={editorConfig}>
<div className="editor-container">
<ToolbarPlugin aditionalTools={aditionalTools} />
<div className="editor-inner">
<RichTextPlugin
contentEditable={<ContentEditable className="editor-input" />}
placeholder={<Placeholder placeholder={placeholder} />}
/>
<OnChangePlugin ignoreInitialChange onChange={onChange} />
</div>
</div>
</LexicalComposer>
Run Code Online (Sandbox Code Playgroud) 我正在使用@emotion/react主题并将主题注入其中,我可以使用useTheme组件访问主题,但无法使用@emotion/styled. 有什么帮助吗?
//libs
import React from 'react';
import styled from '@emotion/styled';
import StylesProvider from '@mui/styles/StylesProvider';
import { ThemeProvider } from '@emotion/react';
const THEME = {
primary: 'red'
}
const StyledText = styled('p')`
color: ${({ theme }) => theme.primary};
`;
function App() {
return (
<StylesProvider injectFirst>
<ThemeProvider theme={THEME}>
<StyledText>test</StyledText>
</ThemeProvider>
</StylesProvider>
);
}
export default App;
here is sample code
Run Code Online (Sandbox Code Playgroud)