change markdown-preview extension
This commit is contained in:
parent
e30d345e9d
commit
4cf56096e1
1 changed files with 46 additions and 0 deletions
46
src/renderer/component/common/markdown-preview.jsx
Normal file
46
src/renderer/component/common/markdown-preview.jsx
Normal file
|
@ -0,0 +1,46 @@
|
|||
// @flow
|
||||
import * as React from 'react';
|
||||
import remark from 'remark';
|
||||
import reactRenderer from 'remark-react';
|
||||
import remarkEmoji from 'remark-emoji';
|
||||
import ExternalLink from 'component/externalLink';
|
||||
import defaultSchema from 'hast-util-sanitize/lib/github.json';
|
||||
|
||||
// Use github sanitation schema
|
||||
const schema = { ...defaultSchema };
|
||||
|
||||
// Extend sanitation schema to support lbry protocol
|
||||
schema.protocols.href[3] = 'lbry';
|
||||
|
||||
type MarkdownProps = {
|
||||
content: string,
|
||||
promptLinks?: boolean,
|
||||
};
|
||||
|
||||
const SimpleLink = ({ href, title, children }) => (
|
||||
<a href={href} title={title}>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
|
||||
const MarkdownPreview = (props: MarkdownProps) => {
|
||||
const { content, externalLinks, promptLinks } = props;
|
||||
const remarkOptions = {
|
||||
sanitize: schema,
|
||||
remarkReactComponents: {
|
||||
a: promptLinks ? ExternalLink : SimpleLink,
|
||||
},
|
||||
};
|
||||
return (
|
||||
<div className="markdown-preview">
|
||||
{
|
||||
remark()
|
||||
.use(remarkEmoji)
|
||||
.use(reactRenderer, remarkOptions)
|
||||
.processSync(content).contents
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MarkdownPreview;
|
Loading…
Reference in a new issue