Refactor markdown preview to minimize unsafe HTML. (#3842)

Fixes INS-805.
This commit is contained in:
John Chadwick 2021-07-23 12:55:47 -07:00 committed by GitHub
parent 0178533e52
commit eb67958846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,16 +117,12 @@ class MarkdownPreview extends PureComponent<Props, State> {
render() { render() {
const { className, heading } = this.props; const { className, heading } = this.props;
const { compiled, renderError } = this.state; const { compiled, renderError } = this.state;
const html = heading ? `<h1>${heading}</h1>\n${compiled}` : compiled;
return ( return (
<div ref={this._setPreviewRef} className={classnames('markdown-preview', className)}> <div ref={this._setPreviewRef} className={classnames('markdown-preview', className)}>
{renderError && <p className="notice error no-margin">Failed to render: {renderError}</p>} {renderError && <p className="notice error no-margin">Failed to render: {renderError}</p>}
<div <div className="markdown-preview__content selectable">
className="markdown-preview__content selectable" {heading ? <h1>{heading}</h1> : null}
dangerouslySetInnerHTML={{ <div dangerouslySetInnerHTML={{ __html: compiled }}></div>
__html: html,
}}>
{/* Set from above */}
</div> </div>
</div> </div>
); );