Files
frontend-app-discussions/src/components/HTMLLoader.jsx
Mehak Nasir 2ea48f6825 Revert build fail (#179)
* fix: dropped support for better-react-mathjax as it is causing build issues

* fix: mathjax package reverted to avoid build issue
2022-06-01 12:29:18 +05:00

31 lines
936 B
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import MathJax from 'react-mathjax-preview';
function HTMLLoader({ htmlNode, componentId, cssClassName }) {
const isLatex = htmlNode.match(/(\${1,2})((?:\\.|.)*)\1/)
|| htmlNode.match(/(\[mathjax](.+?)\[\\mathjax])+/)
|| htmlNode.match(/(\[mathjaxinline](.+?)\[\\mathjaxinline])+/)
|| htmlNode.match(/(\\\[(.+?)\\\])+/);
return (
isLatex ? <MathJax math={htmlNode} id={componentId} className={cssClassName} />
// eslint-disable-next-line react/no-danger
: <div className={cssClassName} id={componentId} dangerouslySetInnerHTML={{ __html: htmlNode }} />
);
}
HTMLLoader.propTypes = {
htmlNode: PropTypes.node.isRequired,
componentId: PropTypes.string,
cssClassName: PropTypes.string,
};
HTMLLoader.defaultProps = {
componentId: null,
cssClassName: '',
};
export default HTMLLoader;