Closed xckevin closed 1 month ago
文档下载后,代码都变成一行了,并且多了一些代码块上的文字。如:
使用代码示例 jsx 代码解读 复制代码
import { useMemo, useState } from "react";import CodeMirror from "rodemirror";import { basicSetup } from "@codemirror/basic-setup";import { oneDark } from "@codemirror/theme-one-dark";import { javascript } from "@codemirror/lang-javascript";import { markdown as langMarkdown } from "@codemirror/lang-markdown";const Editor = () => { const extensions = useMemo(() => [basicSetup, oneDark, javascript(),langMarkdown()], []); const defaultValue = "console.log('Hello world!')"; // remove if you do not need the value const [value, setValue] = useState(defaultValue); return ( <CodeMirror value={defaultValue} onUpdate={(v) => { if (v.docChanged) { setValue(v.state.doc.toString()); } }} extensions={extensions} /> );};export default Editor;
测试地址: https://juejin.cn/post/7403946149914738751
文档下载后,代码都变成一行了,并且多了一些代码块上的文字。如:
import { useMemo, useState } from "react";import CodeMirror from "rodemirror";import { basicSetup } from "@codemirror/basic-setup";import { oneDark } from "@codemirror/theme-one-dark";import { javascript } from "@codemirror/lang-javascript";import { markdown as langMarkdown } from "@codemirror/lang-markdown";const Editor = () => { const extensions = useMemo(() => [basicSetup, oneDark, javascript(),langMarkdown()], []); const defaultValue = "console.log('Hello world!')"; // remove if you do not need the value const [value, setValue] = useState(defaultValue); return ( <CodeMirror value={defaultValue} onUpdate={(v) => { if (v.docChanged) { setValue(v.state.doc.toString()); } }} extensions={extensions} /> );};export default Editor;