add support for lbry protocol on sanitation schema
This commit is contained in:
parent
8127db345b
commit
ae7ae36702
5 changed files with 19 additions and 14 deletions
|
@ -49,6 +49,7 @@
|
|||
"electron-window-state": "^4.1.1",
|
||||
"find-process": "^1.1.0",
|
||||
"formik": "^0.10.4",
|
||||
"hast-util-sanitize": "^1.1.2",
|
||||
"keytar": "^4.2.1",
|
||||
"lbry-redux": "lbryio/lbry-redux",
|
||||
"localforage": "^1.7.1",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { doNotify } from 'lbry-redux';
|
||||
// import { doNavigate } from 'redux/actions/navigation';
|
||||
import { doNavigate } from 'redux/actions/navigation';
|
||||
import ExternalLink from './view';
|
||||
|
||||
const select = () => ({});
|
||||
const perform = dispatch => ({
|
||||
// navigate: (path, params) => dispatch(doNavigate(path, params)),
|
||||
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
||||
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ type Props = {
|
|||
href: string,
|
||||
title?: string,
|
||||
children: React.Node,
|
||||
// navigate: (string, ?{}) => void,
|
||||
navigate: (string, ?{}) => void,
|
||||
openModal: ({ id: string }, { uri: string }) => void,
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,8 @@ class ExternalLink extends React.PureComponent<Props> {
|
|||
};
|
||||
|
||||
createLink() {
|
||||
const { href, title, children, openModal } = this.props;
|
||||
const { href, title, children, openModal, navigate } = this.props;
|
||||
console.info(href);
|
||||
|
||||
// Regex for url protocol
|
||||
const protocolRegex = new RegExp('^(https?|lbry)+:', 'i');
|
||||
|
@ -41,19 +42,14 @@ class ExternalLink extends React.PureComponent<Props> {
|
|||
);
|
||||
}
|
||||
|
||||
/* React-remark blocks the lbry protocol requires an external fix
|
||||
// Return local link if valid lbry uri
|
||||
// Return local link if protocol is lbry uri
|
||||
if (protocol && protocol[0] === 'lbry:') {
|
||||
element = (
|
||||
<Button
|
||||
button="link"
|
||||
title={title}
|
||||
onClick={() => navigate('/show', { uri: href })}
|
||||
>
|
||||
<Button button="link" title={title} onClick={() => navigate('/show', { uri: href })}>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
} */
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,16 @@ import * as React from 'react';
|
|||
import remark from 'remark';
|
||||
import reactRenderer from 'remark-react';
|
||||
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 };
|
||||
|
||||
type TitleProps = { children: React.Node };
|
||||
|
||||
const MarkdownTitle = (props: TitleProps) => {
|
||||
|
@ -15,7 +23,7 @@ const MarkdownTitle = (props: TitleProps) => {
|
|||
const MarkdownPreview = (props: MarkdownProps) => {
|
||||
const { content } = props;
|
||||
const remarkOptions = {
|
||||
sanatize: true,
|
||||
sanitize: schema,
|
||||
remarkReactComponents: {
|
||||
a: ExternalLink,
|
||||
h1: MarkdownTitle,
|
||||
|
|
|
@ -4608,7 +4608,7 @@ hast-to-hyperscript@^4.0.0:
|
|||
trim "0.0.1"
|
||||
unist-util-is "^2.0.0"
|
||||
|
||||
hast-util-sanitize@^1.0.0:
|
||||
hast-util-sanitize@^1.0.0, hast-util-sanitize@^1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/hast-util-sanitize/-/hast-util-sanitize-1.1.2.tgz#d10bd6757a21e59c13abc8ae3530dd3b6d7d679e"
|
||||
dependencies:
|
||||
|
|
Loading…
Add table
Reference in a new issue