diff --git a/frontend/components/Document/Document.js b/frontend/components/Document/Document.js index 93ea3969a..1dd87f0ee 100644 --- a/frontend/components/Document/Document.js +++ b/frontend/components/Document/Document.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PropTypes } from 'react'; import { observer } from 'mobx-react'; import moment from 'moment'; @@ -7,15 +7,40 @@ import PublishingInfo from 'components/PublishingInfo'; import styles from './Document.scss'; -const DocumentHtml = observer((props) => { - return ( -
- ); -}); +@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 ( + + ); + } +} @observer class Document extends React.Component {