DocumentHtml improvement and Enzyme
This commit is contained in:
@ -3,48 +3,14 @@ import { toJS } from 'mobx';
|
||||
import { observer } from 'mobx-react';
|
||||
|
||||
import PublishingInfo from 'components/PublishingInfo';
|
||||
import DocumentHtml from './components/DocumentHtml';
|
||||
|
||||
import styles from './Document.scss';
|
||||
|
||||
@observer
|
||||
class DocumentHtml extends React.Component {
|
||||
static propTypes = {
|
||||
html: PropTypes.string.isRequired,
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
this.setExternalLinks();
|
||||
}
|
||||
|
||||
componentDidUpdate = () => {
|
||||
this.setExternalLinks();
|
||||
}
|
||||
|
||||
setExternalLinks = () => {
|
||||
const links = this.refs.content.querySelectorAll('a');
|
||||
links.forEach(link => {
|
||||
if (link.hostname !== window.location.hostname) {
|
||||
link.target = '_blank'; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
ref="content"
|
||||
className={ styles.document }
|
||||
dangerouslySetInnerHTML={{ __html: this.props.html }}
|
||||
{ ...this.props }
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@observer
|
||||
class Document extends React.Component {
|
||||
static propTypes = {
|
||||
document: React.PropTypes.object.isRequired,
|
||||
document: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -64,6 +30,3 @@ class Document extends React.Component {
|
||||
}
|
||||
|
||||
export default Document;
|
||||
export {
|
||||
DocumentHtml,
|
||||
};
|
||||
|
Reference in New Issue
Block a user