Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # HTML To DraftJS
  2. A library for converting plain HTML to DraftJS Editor content.
  3. Build for use with **[react-draft-wysiwyg](https://github.com/jpuri/react-draft-wysiwyg)**.
  4. ## Installation
  5. ```
  6. npm install html-to-draftjs --save
  7. ```
  8. ## Usage
  9. ```
  10. import { EditorState, ContentState } from 'draft-js';
  11. import htmlToDraft from 'html-to-draftjs';
  12. const blocksFromHtml = htmlToDraft(this.props.content);
  13. const { contentBlocks, entityMap } = blocksFromHtml;
  14. const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap);
  15. const editorState = EditorState.createWithContent(contentState);
  16. ```
  17. ### (optional) customChunkRenderer
  18. Use to define additional html nodes. Only supports atomic blocks.
  19. * _nodeName: string_ - the name of the node, in lowercase
  20. * _node: HTMLElement_ - the parsed node itself
  21. This renderer function is executed before any other html to draft conversion.
  22. Return nothing (or something falsy) to continue with the normal translation.
  23. Example:
  24. ```
  25. htmlToDraft('<hr/>', (nodeName, node) => {
  26. if (nodeName === 'hr') {
  27. return {
  28. type: 'HORIZONTAL_RULE',
  29. mutability: 'MUTABLE',
  30. data: {}
  31. };
  32. }
  33. })
  34. ```
  35. **Take Care:** Plz not use version `1.2.0` it has build issues.