import * as React from "react"; import * as pure from "../../common/pure"; import * as marked from "marked"; import escapeHtml = require("escape-html"); /** * Our CSS file */ require('./markdown.css'); interface Props { markdown: string } /** * Renders markdown */ export class MarkDown extends React.PureComponent { constructor(props: Props) { super(props); } render() { const rendered = toHtml(this.props.markdown); return (
); } } /** Converts an html string to markdown */ export function toHtml(markdown: string) { return ( `
${ marked(escapeHtml(markdown)) // Move hrefs to target blank .replace(/a href=/g, "a target='_blank' href=") // don't want a trailing newline .trim() // Make newlines `
`s .replace(/\n/g, '
') }
` ); }