import React from 'react';
import PropTypes from 'prop-types';

export const ParsedArticle = ({ highlightedHtml, whocolorHtml, parsedArticle }) => {
  const articleHTML = highlightedHtml || whocolorHtml || parsedArticle;
  return (
    <div className="parsed-article" dangerouslySetInnerHTML={{ __html: articleHTML }} />
  );
};

ParsedArticle.propTypes = {
  highlightedHtml: PropTypes.string,
  whocolorHtml: PropTypes.string,
  parsedArticle: PropTypes.string
};

export default ParsedArticle;

import React from 'react';
import PropTypes from 'prop-types';


const wikilinkMatcher = new RegExp('<a href=', 'g');
const blankTargetLink = '<a target="_blank" href=';

export const ParsedArticle = ({ highlightedHtml, whocolorHtml, parsedArticle }) => {
  let articleHTML = highlightedHtml || whocolorHtml || parsedArticle;

  // This sets `target="_blank"` for all of the link in the article HTML,
  // so that clicking one will open it in a new tab.
  articleHTML = articleHTML?.replace(wikilinkMatcher, blankTargetLink);

  return (
    <div className="parsed-article" dangerouslySetInnerHTML={{ __html: articleHTML }} />
  );
};

ParsedArticle.propTypes = {
  highlightedHtml: PropTypes.string,
  whocolorHtml: PropTypes.string,
  parsedArticle: PropTypes.string
};

export default ParsedArticle;

Add target="_blanks" to typical links in ArticleViewer
Add target="_blanks" to typical links in ArticleViewer

This cleanly handles standard wikilinks in Wikipedia articles, so that clicking one will open the Wikipedia article in a new tab instead of navigating the user away from the Dashboard.

Wikidata links, however, are formatted differently, with a `title` attribute before the `href` and relative links instead of absolute ones... so this change doesn't affect Wikidata items, which have broken links in ArticleViewer anyway.
