Skip to content

Commit 90cfa00

Browse files
author
David Silva
committed
Created a link Renderer to use in the React Markdown component
1 parent b603cbf commit 90cfa00

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/components/misc/linkRenderer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import { ensureUrl } from '../../constants/utils';
4+
5+
class linkRenderer extends Component {
6+
static propTypes = {
7+
href: PropTypes.string,
8+
children: PropTypes.oneOfType([
9+
PropTypes.node,
10+
PropTypes.arrayOf(PropTypes.node),
11+
]),
12+
}
13+
14+
render() {
15+
const url = ensureUrl(this.props.href);
16+
return(
17+
<a href={ url } target={ url.startsWith('/') ? '' : '_blank' }>
18+
{ this.props.children }
19+
</a>
20+
);
21+
}
22+
}
23+
24+
export default linkRenderer;

0 commit comments

Comments
 (0)