New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

draftjs-to-html

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draftjs-to-html - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

3

lib/draftjs-to-html.js

@@ -1,2 +0,1 @@

module.exports=function(t){function e(r){if(n[r])return n[r].exports;var a=n[r]={exports:{},id:r,loaded:!1};return t[r].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){t.exports=n(3)},function(t,e,n){"use strict";function r(t){return t&&T[t]}function a(t){var e="";return(0,L.forEach)(t,function(t,n){n&&(e+=t+":"+n+";")}),e}function u(t,e){var n=[],r=0;return t.forEach(function(t){t.offset>r&&n.push({start:r,end:t.offset}),n.push({start:t.offset,end:t.offset+t.length,entityKey:t.key}),r=t.offset+t.length}),r<e&&n.push({start:r,end:e}),n}function s(t){return!!(t.entityRanges.length>0&&(0,L.isEmptyString)(t.text))}function i(t){var e=t.text,n=t.inlineStyleRanges,r={BOLD:new Array(e.length),ITALIC:new Array(e.length),UNDERLINE:new Array(e.length),STRIKETHROUGH:new Array(e.length),CODE:new Array(e.length),SUPERSCRIPT:new Array(e.length),SUBSCRIPT:new Array(e.length),COLOR:new Array(e.length),BGCOLOR:new Array(e.length),FONTSIZE:new Array(e.length),FONTFAMILY:new Array(e.length),length:e.length};return n&&n.length>0&&n.forEach(function(t){for(var e=t.offset,n=e+t.length,a=e;a<n;a+=1)t.style.startsWith("color-")?r.COLOR[a]=t.style.substring(6):t.style.startsWith("bgcolor-")?r.BGCOLOR[a]=t.style.substring(8):t.style.startsWith("fontsize-")?r.FONTSIZE[a]=t.style.substring(9):t.style.startsWith("fontfamily-")?r.FONTFAMILY[a]=t.style.substring(11):r[t.style]&&(r[t.style][a]=!0)}),r}function o(t,e){var n={};return t.COLOR[e]&&(n.COLOR=t.COLOR[e]),t.BGCOLOR[e]&&(n.BGCOLOR=t.BGCOLOR[e]),t.FONTSIZE[e]&&(n.FONTSIZE=t.FONTSIZE[e]),t.FONTFAMILY[e]&&(n.FONTFAMILY=t.FONTFAMILY[e]),t.UNDERLINE[e]&&(n.UNDERLINE=!0),t.ITALIC[e]&&(n.ITALIC=!0),t.BOLD[e]&&(n.BOLD=!0),t.STRIKETHROUGH[e]&&(n.STRIKETHROUGH=!0),t.CODE[e]&&(n.CODE=!0),t.SUBSCRIPT[e]&&(n.SUBSCRIPT=!0),t.SUPERSCRIPT[e]&&(n.SUPERSCRIPT=!0),n}function l(t,e,n){var r=!0;return n>0&&n<t.length?e.forEach(function(e){r=r&&t[e][n]===t[e][n-1]}):r=!1,r}function h(t,e){return"BOLD"===t?"<strong>"+e+"</strong>":"ITALIC"===t?"<em>"+e+"</em>":"UNDERLINE"===t?"<ins>"+e+"</ins>":"STRIKETHROUGH"===t?"<del>"+e+"</del>":"CODE"===t?"<code>"+e+"</code>":"SUPERSCRIPT"===t?"<sup>"+e+"</sup>":"SUBSCRIPT"===t?"<sub>"+e+"</sub>":e}function f(t){if(t&&t.length>0){var e=t.map(function(t){switch(t){case"\n":return"<br>\n";case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";default:return t}});return e.join("")}return""}function c(t){var e=t.styles,n=t.text,r=f(n);if(e&&(e.COLOR||e.BGCOLOR||e.FONTSIZE||e.FONTFAMILY)){var a='style="';return e.COLOR&&(a+="color: "+e.COLOR+";"),e.BGCOLOR&&(a+="background-color: "+e.BGCOLOR+";"),e.FONTSIZE&&(a+="font-size: "+e.FONTSIZE+"px;"),e.FONTFAMILY&&(a+="font-family: "+e.FONTFAMILY+";"),a+='"',"<span "+a+">"+r+"</span>"}return r}function p(t,e,n){var r=t[e];return"MENTION"===r.type?'<a href="'+r.data.url+'" class="wysiwyg-mention" data-mention data-value="'+r.data.value+'">'+n+"</a>":"LINK"===r.type?'<a href="'+r.data.url+'">'+n+"</a>":"IMAGE"===r.type?'<img src="'+r.data.src+'" style="float:'+(r.data.alignment||"none")+";height: "+r.data.height+";width: "+r.data.width+'"/>':"EMBEDDED_LINK"===r.type?'<iframe width="'+r.data.width+'" height="'+r.data.height+'" src="'+r.data.src+'" frameBorder="0" allowFullScreen />':n}function g(t,e,n,r){var a=[],u=t.text;if(u.length>0)for(var s=i(t),h=void 0,f=n;f<r;f+=1)f!==n&&l(s,e,f)?(h.text.push(u[f]),h.end=f+1):(h={styles:o(s,f),text:[u[f]],start:f,end:f+1},a.push(h));return a}function O(t){if(t){for(var e=t,n=0;n<e.length&&" "===t[n];n+=1)e=e.replace(" ","&nbsp;");return e}return t}function d(t){if(t){for(var e=t,n=e.length-1;n>=0&&" "===e[n];n-=1)e=e.substring(0,n)+"&nbsp;"+e.substring(n+1);return e}return t}function y(t,e){var n=e;return(0,L.forEach)(t,function(t,e){n=h(t,n,e)}),n}function I(t,e){var n=g(t,["COLOR","BGCOLOR","FONTSIZE","FONTFAMILY"],e.start,e.end),r="";return n.forEach(function(t){r+=c(t)}),r=y(e.styles,r)}function E(t,e,n){var r=[],a=g(t,["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"],n.start,n.end);a.forEach(function(e){r.push(I(t,e))});var u=r.join("");return void 0!==n.entityKey&&null!==n.entityKey&&(u=p(e,n.entityKey,u)),u}function R(t,e){var n=[],r=u(t.entityRanges,t.text.length);return r.forEach(function(a,u){var s=E(t,e,a);0===u&&(s=O(s)),u===r.length-1&&(s=d(s)),n.push(s)}),n.join("")}function v(t,e,n){var u=[];if(s(t))u.push(p(e,t.entityRanges[0].key));else{var i=r(t.type);if(i){u.push("<"+i);var o=a(t.data);o&&u.push(' style="'+o+'"'),n&&u.push(' dir = "auto"'),u.push(">"),u.push(R(t,e)),u.push("</"+i+">")}}return u.push("\n"),u.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.getBlockTag=r,e.getBlockStyle=a,e.getStylesAtOffset=o,e.sameStyleAsPrevious=l,e.addInlineStyleMarkup=h,e.addStylePropertyMarkup=c,e.trimLeadingZeros=O,e.trimTrailingZeros=d,e.getBlockInnerMarkup=R,e.getBlockMarkup=v;var L=n(2),T={unstyled:"p","header-one":"h1","header-two":"h2","header-three":"h3","header-four":"h4","header-five":"h5","header-six":"h6","unordered-list-item":"ul","ordered-list-item":"ol",blockquote:"blockquote"}},function(t,e){"use strict";function n(t,e){if(t)for(var n in t)({}).hasOwnProperty.call(t,n)&&e(n,t[n])}function r(t){return void 0===t||null===t||0===t.length||0===t.trim().length}Object.defineProperty(e,"__esModule",{value:!0}),e.forEach=n,e.isEmptyString=r},function(t,e,n){"use strict";function r(t,e){var n=[];return t&&!function(){var r=t.blocks,s=t.entityMap;r&&r.length>0&&!function(){var t=[];if(r.forEach(function(r){if((0,u.isList)(r.type))t.push(r);else{if(t.length>0){var i=(0,u.getListMarkup)(t,s);n.push(i),t=[]}var o=(0,a.getBlockMarkup)(r,s,e);n.push(o)}}),t.length>0){var i=(0,u.getListMarkup)(t,s);n.push(i),t=[]}}()}(),n.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var a=n(1),u=n(4)},function(t,e,n){"use strict";function r(t){return"unordered-list-item"===t||"ordered-list-item"===t}function a(t,e){var n=[],r=[],s=void 0;return t.forEach(function(t){var i=!1;if(s?s.type!==t.type?(n.push("</"+(0,u.getBlockTag)(s.type)+">\n"),n.push("<"+(0,u.getBlockTag)(t.type)+">\n")):s.depth===t.depth?r&&r.length>0&&(n.push(a(r)),r=[]):(i=!0,r.push(t)):n.push("<"+(0,u.getBlockTag)(t.type)+">\n"),!i){n.push("<li");var o=(0,u.getBlockStyle)(t.data);o&&n.push(' style="'+o+'"'),n.push(">"),n.push((0,u.getBlockInnerMarkup)(t,e)),n.push("</li>\n"),s=t}}),r&&r.length>0&&n.push(a(r)),n.push("</"+(0,u.getBlockTag)(s.type)+">\n"),n.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.isList=r,e.getListMarkup=a;var u=n(1)}]);
//# sourceMappingURL=draftjs-to-html.js.map
module.exports=function(t){function e(r){if(n[r])return n[r].exports;var u=n[r]={i:r,l:!1,exports:{}};return t[r].call(u.exports,u,u.exports,e),u.l=!0,u.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,n){"use strict";function r(t){return t&&T[t]}function u(t){var e="";return(0,L.forEach)(t,function(t,n){n&&(e+=t+":"+n+";")}),e}function a(t,e){var n=[],r=0;return t.forEach(function(t){t.offset>r&&n.push({start:r,end:t.offset}),n.push({start:t.offset,end:t.offset+t.length,entityKey:t.key}),r=t.offset+t.length}),r<e&&n.push({start:r,end:e}),n}function i(t){return!!(t.entityRanges.length>0&&(0,L.isEmptyString)(t.text)||"atomic"===t.type)}function o(t){var e=t.text,n=t.inlineStyleRanges,r={BOLD:new Array(e.length),ITALIC:new Array(e.length),UNDERLINE:new Array(e.length),STRIKETHROUGH:new Array(e.length),CODE:new Array(e.length),SUPERSCRIPT:new Array(e.length),SUBSCRIPT:new Array(e.length),COLOR:new Array(e.length),BGCOLOR:new Array(e.length),FONTSIZE:new Array(e.length),FONTFAMILY:new Array(e.length),length:e.length};return n&&n.length>0&&n.forEach(function(t){for(var e=t.offset,n=e+t.length,u=e;u<n;u+=1)t.style.startsWith("color-")?r.COLOR[u]=t.style.substring(6):t.style.startsWith("bgcolor-")?r.BGCOLOR[u]=t.style.substring(8):t.style.startsWith("fontsize-")?r.FONTSIZE[u]=t.style.substring(9):t.style.startsWith("fontfamily-")?r.FONTFAMILY[u]=t.style.substring(11):r[t.style]&&(r[t.style][u]=!0)}),r}function s(t,e){var n={};return t.COLOR[e]&&(n.COLOR=t.COLOR[e]),t.BGCOLOR[e]&&(n.BGCOLOR=t.BGCOLOR[e]),t.FONTSIZE[e]&&(n.FONTSIZE=t.FONTSIZE[e]),t.FONTFAMILY[e]&&(n.FONTFAMILY=t.FONTFAMILY[e]),t.UNDERLINE[e]&&(n.UNDERLINE=!0),t.ITALIC[e]&&(n.ITALIC=!0),t.BOLD[e]&&(n.BOLD=!0),t.STRIKETHROUGH[e]&&(n.STRIKETHROUGH=!0),t.CODE[e]&&(n.CODE=!0),t.SUBSCRIPT[e]&&(n.SUBSCRIPT=!0),t.SUPERSCRIPT[e]&&(n.SUPERSCRIPT=!0),n}function l(t,e,n){var r=!0;return n>0&&n<t.length?e.forEach(function(e){r=r&&t[e][n]===t[e][n-1]}):r=!1,r}function f(t,e){return"BOLD"===t?"<strong>"+e+"</strong>":"ITALIC"===t?"<em>"+e+"</em>":"UNDERLINE"===t?"<ins>"+e+"</ins>":"STRIKETHROUGH"===t?"<del>"+e+"</del>":"CODE"===t?"<code>"+e+"</code>":"SUPERSCRIPT"===t?"<sup>"+e+"</sup>":"SUBSCRIPT"===t?"<sub>"+e+"</sub>":e}function c(t){if(t&&t.length>0){var e=t.map(function(t){switch(t){case"\n":return"<br>\n";case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";default:return t}});return e.join("")}return""}function h(t){var e=t.styles,n=t.text,r=c(n);if(e&&(e.COLOR||e.BGCOLOR||e.FONTSIZE||e.FONTFAMILY)){var u='style="';return e.COLOR&&(u+="color: "+e.COLOR+";"),e.BGCOLOR&&(u+="background-color: "+e.BGCOLOR+";"),e.FONTSIZE&&(u+="font-size: "+e.FONTSIZE+"px;"),e.FONTFAMILY&&(u+="font-family: "+e.FONTFAMILY+";"),u+='"',"<span "+u+">"+r+"</span>"}return r}function p(t,e,n,r){var u=t[e];if("function"==typeof r){var a=r(u,n);if(a)return a}if("MENTION"===u.type)return'<a href="'+u.data.url+'" class="wysiwyg-mention" data-mention data-value="'+u.data.value+'">'+n+"</a>";if("LINK"===u.type){var i=u.data.target||"_self";return'<a href="'+u.data.url+'" target="'+i+'" >'+n+"</a>"}return"IMAGE"===u.type?'<img src="'+u.data.src+'" style="float:'+(u.data.alignment||"none")+";height: "+u.data.height+";width: "+u.data.width+'"/>':"EMBEDDED_LINK"===u.type?'<iframe width="'+u.data.width+'" height="'+u.data.height+'" src="'+u.data.src+'" frameBorder="0" allowFullScreen />':n}function g(t,e,n,r){var u=[],a=t.text;if(a.length>0)for(var i=o(t),f=void 0,c=n;c<r;c+=1)c!==n&&l(i,e,c)?(f.text.push(a[c]),f.end=c+1):(f={styles:s(i,c),text:[a[c]],start:c,end:c+1},u.push(f));return u}function y(t){if(t){for(var e=t,n=0;n<e.length&&" "===t[n];n+=1)e=e.replace(" ","&nbsp;");return e}return t}function O(t){if(t){for(var e=t,n=e.length-1;n>=0&&" "===e[n];n-=1)e=e.substring(0,n)+"&nbsp;"+e.substring(n+1);return e}return t}function d(t,e){var n=e;return(0,L.forEach)(t,function(t,e){n=f(t,n,e)}),n}function v(t,e){var n=g(t,["COLOR","BGCOLOR","FONTSIZE","FONTFAMILY"],e.start,e.end),r="";return n.forEach(function(t){r+=h(t)}),r=d(e.styles,r)}function I(t,e,n,r){var u=[],a=g(t,["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"],n.start,n.end);a.forEach(function(e){u.push(v(t,e))});var i=u.join("");return void 0!==n.entityKey&&null!==n.entityKey&&(i=p(e,n.entityKey,i,r)),i}function E(t,e,n){var r=[],u=a(t.entityRanges,t.text.length);return u.forEach(function(a,i){var o=I(t,e,a,n);0===i&&(o=y(o)),i===u.length-1&&(o=O(o)),r.push(o)}),r.join("")}function R(t,e,n,a){var o=[];if(i(t))o.push(p(e,t.entityRanges[0].key,void 0,a));else{var s=r(t.type);if(s){o.push("<"+s);var l=u(t.data);l&&o.push(' style="'+l+'"'),n&&o.push(' dir = "auto"'),o.push(">"),o.push(E(t,e,a)),o.push("</"+s+">")}}return o.push("\n"),o.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.getBlockTag=r,e.getBlockStyle=u,e.getStylesAtOffset=s,e.sameStyleAsPrevious=l,e.addInlineStyleMarkup=f,e.addStylePropertyMarkup=h,e.trimLeadingZeros=y,e.trimTrailingZeros=O,e.getBlockInnerMarkup=E,e.getBlockMarkup=R;var L=n(2),T={unstyled:"p","header-one":"h1","header-two":"h2","header-three":"h3","header-four":"h4","header-five":"h5","header-six":"h6","unordered-list-item":"ul","ordered-list-item":"ol",blockquote:"blockquote"}},function(t,e,n){"use strict";function r(t,e,n){var r=[];return t&&!function(){var i=t.blocks,o=t.entityMap;i&&i.length>0&&!function(){var t=[];if(i.forEach(function(i){if((0,a.isList)(i.type))t.push(i);else{if(t.length>0){var s=(0,a.getListMarkup)(t,o,n);r.push(s),t=[]}var l=(0,u.getBlockMarkup)(i,o,e,n);r.push(l)}}),t.length>0){var s=(0,a.getListMarkup)(t,o,n);r.push(s),t=[]}}()}(),r.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var u=n(0),a=n(3)},function(t,e,n){"use strict";function r(t,e){if(t)for(var n in t)({}).hasOwnProperty.call(t,n)&&e(n,t[n])}function u(t){return void 0===t||null===t||0===t.length||0===t.trim().length}Object.defineProperty(e,"__esModule",{value:!0}),e.forEach=r,e.isEmptyString=u},function(t,e,n){"use strict";function r(t){return"unordered-list-item"===t||"ordered-list-item"===t}function u(t,e,n){var r=[],i=[],o=void 0;return t.forEach(function(t){var s=!1;if(o?o.type!==t.type?(r.push("</"+(0,a.getBlockTag)(o.type)+">\n"),r.push("<"+(0,a.getBlockTag)(t.type)+">\n")):o.depth===t.depth?i&&i.length>0&&(r.push(u(i,void 0,n)),i=[]):(s=!0,i.push(t)):r.push("<"+(0,a.getBlockTag)(t.type)+">\n"),!s){r.push("<li");var l=(0,a.getBlockStyle)(t.data);l&&r.push(' style="'+l+'"'),r.push(">"),r.push((0,a.getBlockInnerMarkup)(t,e,n)),r.push("</li>\n"),o=t}}),i&&i.length>0&&r.push(u(i,void 0,n)),r.push("</"+(0,a.getBlockTag)(o.type)+">\n"),r.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.isList=r,e.getListMarkup=u;var a=n(0)},function(t,e,n){t.exports=n(1)}]);
{
"name": "draftjs-to-html",
"version": "0.5.1",
"version": "0.6.0",
"description": "A library for draftjs to html conversion.",
"main": "lib/draftjs-to-html.js",
"devDependencies": {
"babel-core": "^6.21.0",
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-flow-strip-types": "^6.21.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"babel-register": "^6.18.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-stage-0": "^6.22.0",
"babel-register": "^6.22.0",
"chai": "^3.5.0",
"draft-js": "^0.9.1",
"enzyme": "^2.7.0",
"eslint": "^3.13.1",
"draft-js": "^0.10.0",
"enzyme": "^2.7.1",
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-mocha": "^4.8.0",
"eslint-plugin-react": "^6.9.0",
"flow-bin": "^0.37.4",
"jsdom": "^9.9.1",
"flow-bin": "^0.38.0",
"jsdom": "^9.10.0",
"mocha": "^3.2.0",

@@ -32,4 +32,4 @@ "react": "^15.4.2",

"sinon": "^1.17.7",
"webpack": "^1.14.0",
"webpack-dev-middleware": "^1.9.0"
"webpack": "^2.2.1",
"webpack-dev-middleware": "^1.10.0"
},

@@ -36,0 +36,0 @@ "repository": {

@@ -17,3 +17,3 @@ # DraftJS TO HTML

const rawContentState = convertToRaw(editorState.getCurrentContent());
const markup = draftToHtml(contentState, directional);
const markup = draftToHtml(contentState, directional, customEntityTransform);
```

@@ -60,7 +60,9 @@

9. Adding style property to block tag for block level styles like text-align: `<p style="text-align: right">text</p>`.
9. `customEntityTransform` can be used for transformation of a custom entity block to html.
10. RTL, if directional function parameter is true, generated blocks have property `dir = "auto"` thus they get aligned according to bidi algorithm.
10. Adding style property to block tag for block level styles like text-align: `<p style="text-align: right">text</p>`.
11. RTL, if directional function parameter is true, generated blocks have property `dir = "auto"` thus they get aligned according to bidi algorithm.
## License
MIT.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc