@20minutes/draft-convert 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +29 -0
  2. package/dist/draft-convert.js +440 -0
  3. package/dist/draft-convert.min.js +1 -0
  4. package/esm/blockEntities.js +67 -0
  5. package/esm/blockInlineStyles.js +98 -0
  6. package/esm/convertFromHTML.js +537 -0
  7. package/esm/convertToHTML.js +107 -0
  8. package/esm/default/defaultBlockHTML.js +31 -0
  9. package/esm/default/defaultInlineHTML.js +18 -0
  10. package/esm/encodeBlock.js +44 -0
  11. package/esm/index.js +4 -0
  12. package/esm/util/accumulateFunction.js +9 -0
  13. package/esm/util/blockTypeObjectFunction.js +9 -0
  14. package/esm/util/getBlockTags.js +27 -0
  15. package/esm/util/getElementHTML.js +36 -0
  16. package/esm/util/getElementTagLength.js +20 -0
  17. package/esm/util/getNestedBlockTags.js +29 -0
  18. package/esm/util/parseHTML.js +18 -0
  19. package/esm/util/rangeSort.js +6 -0
  20. package/esm/util/splitReactElement.js +18 -0
  21. package/esm/util/styleObjectFunction.js +8 -0
  22. package/esm/util/updateMutation.js +48 -0
  23. package/lib/blockEntities.js +74 -0
  24. package/lib/blockInlineStyles.js +105 -0
  25. package/lib/convertFromHTML.js +544 -0
  26. package/lib/convertToHTML.js +114 -0
  27. package/lib/default/defaultBlockHTML.js +37 -0
  28. package/lib/default/defaultInlineHTML.js +25 -0
  29. package/lib/encodeBlock.js +51 -0
  30. package/lib/index.js +27 -0
  31. package/lib/util/accumulateFunction.js +15 -0
  32. package/lib/util/blockTypeObjectFunction.js +15 -0
  33. package/lib/util/getBlockTags.js +34 -0
  34. package/lib/util/getElementHTML.js +43 -0
  35. package/lib/util/getElementTagLength.js +27 -0
  36. package/lib/util/getNestedBlockTags.js +36 -0
  37. package/lib/util/parseHTML.js +24 -0
  38. package/lib/util/rangeSort.js +12 -0
  39. package/lib/util/splitReactElement.js +24 -0
  40. package/lib/util/styleObjectFunction.js +14 -0
  41. package/lib/util/updateMutation.js +55 -0
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -8,5 +8,34 @@
8
8
  Forked version:
9
9
  - with deps up to date
10
10
  - CI on GitHub Actions
11
+ - new [`validateHTML`](#validatehtml-option-of-converttohtml) function parameter for `convertToHTML`
11
12
 
12
13
  For the official readme, [check the official project](https://github.com/HubSpot/draft-convert).
14
+
15
+ ## `validateHTML` (option of `convertToHTML`)
16
+
17
+ `validateHTML` take the final HTML of the current block as parameter and must return a boolean saying if every thing is ok.
18
+
19
+ We do have some custom entity/block generation and sometimes, the produced HTML might be wrong. So we validate it using ReactDomServer, like:
20
+
21
+
22
+ ```js
23
+ import ReactDOMServer from 'react-dom/server'
24
+ import { Parser as HtmlToReactParser } from 'html-to-react'
25
+
26
+ // ...
27
+
28
+ const html = convertToHTML({
29
+ // ...
30
+ validateHTML: (html) => {
31
+ try {
32
+ const htmlToReactParser = HtmlToReactParser()
33
+
34
+ ReactDOMServer.renderToString(htmlToReactParser.parse(html))
35
+
36
+ return true
37
+ } catch (e) {
38
+ return false
39
+ }
40
+ })(editorState.getCurrentContent());
41
+ ````