RevisionBody.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class RevisionBody extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. }
  7. componentDidMount() {
  8. if (MathJax != null && this.props.isMathJaxEnabled && this.props.renderMathJaxOnInit) {
  9. const intervalId = setInterval(() => {
  10. if (MathJax.isReady) {
  11. this.renderMathJax();
  12. clearInterval(intervalId);
  13. }
  14. }, 100);
  15. }
  16. }
  17. componentDidUpdate() {
  18. if (MathJax != null && this.props.isMathJaxEnabled && this.props.renderMathJaxInRealtime) {
  19. this.renderMathJax();
  20. }
  21. }
  22. renderMathJax() {
  23. MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.element]);
  24. }
  25. generateInnerHtml(html) {
  26. return {__html: html};
  27. }
  28. render() {
  29. return (
  30. <div
  31. ref={(elm) => {
  32. this.element = elm;
  33. if (this.props.inputRef != null) {
  34. this.props.inputRef(elm);
  35. }
  36. }}
  37. className="wiki" dangerouslySetInnerHTML={this.generateInnerHtml(this.props.html)}>
  38. </div>
  39. )
  40. }
  41. }
  42. RevisionBody.propTypes = {
  43. html: PropTypes.string,
  44. inputRef: PropTypes.func, // for getting div element
  45. isMathJaxEnabled: PropTypes.bool,
  46. renderMathJaxOnInit: PropTypes.bool,
  47. renderMathJaxInRealtime: PropTypes.bool,
  48. };