Skip to content

Commit

Permalink
feat: markdown 图片语法中支持 dataURL 格式
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Mar 22, 2023
1 parent 7b31b0f commit 971de9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/admin/src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import { Heading } from './plugins/heading';
import { customCodeBlock } from './plugins/codeBlock';
import { LinkTarget } from './plugins/linkTarget';

const sanitize = (schema) => {
schema.protocols.src.push('data')
return schema
}

export default function EditorComponent(props: {
value: string;
onChange: (string: string) => void;
Expand Down Expand Up @@ -65,7 +70,7 @@ export default function EditorComponent(props: {
plugins={plugins}
onChange={props.onChange}
locale={cn}

sanitize={sanitize}
uploadImages={async (files: File[]) => {
setLoading(true);
const res = [];
Expand Down
7 changes: 5 additions & 2 deletions packages/website/components/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ const plugins = [
LinkTarget(),
Heading(),
]

const sanitize = (schema) => {
schema.protocols.src.push('data')
return schema
}
export default function ({ content }: { content: string }) {
return <div className="markdown-body">
<Viewer value={content} plugins={plugins} remarkRehype={{ allowDangerousHtml: true }} />
<Viewer value={content} plugins={plugins} remarkRehype={{ allowDangerousHtml: true }} sanitize={sanitize} />
</div>
}

0 comments on commit 971de9a

Please sign in to comment.