Preview.js 789 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class Preview extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. }
  7. componentDidUpdate() {
  8. const MathJax = window.MathJax;
  9. if (MathJax != null) {
  10. MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.element]);
  11. }
  12. }
  13. generateInnerHtml(html) {
  14. return {__html: html};
  15. }
  16. render() {
  17. return (
  18. <div
  19. ref={(elm) => {
  20. this.element = elm;
  21. this.props.inputRef(elm);
  22. }}
  23. className="wiki page-editor-preview-body" dangerouslySetInnerHTML={this.generateInnerHtml(this.props.html)}>
  24. </div>
  25. )
  26. }
  27. }
  28. Preview.propTypes = {
  29. html: PropTypes.string,
  30. inputRef: PropTypes.func.isRequired, // for getting div element
  31. };