mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-28 16:01:26 +00:00
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",
|
"electron-window-state": "^4.1.1",
|
||||||
"find-process": "^1.1.0",
|
"find-process": "^1.1.0",
|
||||||
"formik": "^0.10.4",
|
"formik": "^0.10.4",
|
||||||
|
"hast-util-sanitize": "^1.1.2",
|
||||||
"keytar": "^4.2.1",
|
"keytar": "^4.2.1",
|
||||||
"lbry-redux": "lbryio/lbry-redux",
|
"lbry-redux": "lbryio/lbry-redux",
|
||||||
"localforage": "^1.7.1",
|
"localforage": "^1.7.1",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doNotify } from 'lbry-redux';
|
import { doNotify } from 'lbry-redux';
|
||||||
// import { doNavigate } from 'redux/actions/navigation';
|
import { doNavigate } from 'redux/actions/navigation';
|
||||||
import ExternalLink from './view';
|
import ExternalLink from './view';
|
||||||
|
|
||||||
const select = () => ({});
|
const select = () => ({});
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
// navigate: (path, params) => dispatch(doNavigate(path, params)),
|
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
||||||
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ type Props = {
|
||||||
href: string,
|
href: string,
|
||||||
title?: string,
|
title?: string,
|
||||||
children: React.Node,
|
children: React.Node,
|
||||||
// navigate: (string, ?{}) => void,
|
navigate: (string, ?{}) => void,
|
||||||
openModal: ({ id: string }, { uri: string }) => void,
|
openModal: ({ id: string }, { uri: string }) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ class ExternalLink extends React.PureComponent<Props> {
|
||||||
};
|
};
|
||||||
|
|
||||||
createLink() {
|
createLink() {
|
||||||
const { href, title, children, openModal } = this.props;
|
const { href, title, children, openModal, navigate } = this.props;
|
||||||
|
console.info(href);
|
||||||
|
|
||||||
// Regex for url protocol
|
// Regex for url protocol
|
||||||
const protocolRegex = new RegExp('^(https?|lbry)+:', 'i');
|
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 protocol is lbry uri
|
||||||
// Return local link if valid lbry uri
|
|
||||||
if (protocol && protocol[0] === 'lbry:') {
|
if (protocol && protocol[0] === 'lbry:') {
|
||||||
element = (
|
element = (
|
||||||
<Button
|
<Button button="link" title={title} onClick={() => navigate('/show', { uri: href })}>
|
||||||
button="link"
|
|
||||||
title={title}
|
|
||||||
onClick={() => navigate('/show', { uri: href })}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
} */
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,16 @@ import * as React from 'react';
|
||||||
import remark from 'remark';
|
import remark from 'remark';
|
||||||
import reactRenderer from 'remark-react';
|
import reactRenderer from 'remark-react';
|
||||||
import ExternalLink from 'component/externalLink';
|
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 MarkdownProps = { content: string };
|
||||||
|
|
||||||
type TitleProps = { children: React.Node };
|
type TitleProps = { children: React.Node };
|
||||||
|
|
||||||
const MarkdownTitle = (props: TitleProps) => {
|
const MarkdownTitle = (props: TitleProps) => {
|
||||||
|
@ -15,7 +23,7 @@ const MarkdownTitle = (props: TitleProps) => {
|
||||||
const MarkdownPreview = (props: MarkdownProps) => {
|
const MarkdownPreview = (props: MarkdownProps) => {
|
||||||
const { content } = props;
|
const { content } = props;
|
||||||
const remarkOptions = {
|
const remarkOptions = {
|
||||||
sanatize: true,
|
sanitize: schema,
|
||||||
remarkReactComponents: {
|
remarkReactComponents: {
|
||||||
a: ExternalLink,
|
a: ExternalLink,
|
||||||
h1: MarkdownTitle,
|
h1: MarkdownTitle,
|
||||||
|
|
|
@ -4608,7 +4608,7 @@ hast-to-hyperscript@^4.0.0:
|
||||||
trim "0.0.1"
|
trim "0.0.1"
|
||||||
unist-util-is "^2.0.0"
|
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"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/hast-util-sanitize/-/hast-util-sanitize-1.1.2.tgz#d10bd6757a21e59c13abc8ae3530dd3b6d7d679e"
|
resolved "https://registry.yarnpkg.com/hast-util-sanitize/-/hast-util-sanitize-1.1.2.tgz#d10bd6757a21e59c13abc8ae3530dd3b6d7d679e"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Add table
Reference in a new issue