No Description

index.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.state = {
  26. mdeState: null,
  27. };
  28. this.converter = new Showdown.Converter({
  29. tables: true,
  30. simplifiedAutoLink: true,
  31. strikethrough: true,
  32. tasklists: true
  33. });
  34. }
  35. handleValueChange = (mdeState) => {
  36. this.setState({mdeState});
  37. }
  38. render() {
  39. return (
  40. <div className="container">
  41. <ReactMde
  42. layout="horizontal"
  43. buttonContentOptions={{ iconProvider }}
  44. onChange={this.handleValueChange}
  45. editorState={this.state.mdeState}
  46. generateMarkdownPreview={(markdown) => Promise.resolve(this.converter.makeHtml(markdown))}
  47. />
  48. </div>
  49. );
  50. }
  51. }