Нет описания

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as React from "react";
  2. import ReactMde from 'react-mde';
  3. import * as Showdown from "showdown";
  4. import 'react-mde/lib/styles/css/react-mde-all.css';
  5. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  6. const icons = {
  7. "bold": <FontAwesomeIcon icon="bold" />,
  8. "heading": <FontAwesomeIcon icon="heading" />,
  9. "italic": <FontAwesomeIcon icon="italic" />,
  10. "strikethrough": <FontAwesomeIcon icon="strikethrough" />,
  11. "link": <FontAwesomeIcon icon="link" />,
  12. "quote-right": <FontAwesomeIcon icon="quote-right" />,
  13. "code": <FontAwesomeIcon icon="code" />,
  14. "image": <FontAwesomeIcon icon="image" />,
  15. "list-ul": <FontAwesomeIcon icon="list-ul" />,
  16. "list-ol": <FontAwesomeIcon icon="list-ol" />,
  17. "tasks": <FontAwesomeIcon icon="tasks" />,
  18. };
  19. const iconProvider = (name) => {
  20. return icons[name] || "❓";
  21. };
  22. export default class MarkdownEditor extends React.Component {
  23. constructor(props) {
  24. super(props);
  25. this.converter = new Showdown.Converter({tables: true, simplifiedAutoLink: true});
  26. }
  27. handleValueChange = (mdeState) => {
  28. this.setState({mdeState});
  29. }
  30. render() {
  31. const defaultProps = {
  32. layout: 'horizontal',
  33. buttonContentOptions: { iconProvider },
  34. generateMarkdownPreview: (markdown) => Promise.resolve(this.converter.makeHtml(markdown)),
  35. }
  36. const props= {
  37. ...this.props,
  38. ...defaultProps,
  39. }
  40. return (
  41. <ReactMde {...props} />
  42. );
  43. }
  44. }