draftjs-to-markdown
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.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=2)}([function(t,e,n){"use strict";function r(t){return t.type&&N[t.type]}function o(t){return!!(t.entityRanges.length>0&&(0,C.isEmptyString)(t.text))}function u(t,e,n,r){var o=t[e];if("function"==typeof r){var u=r(o,n);if(u)return u}return"MENTION"===o.type?"["+n+"]("+o.data.url+")":"LINK"===o.type?"["+o.data.title+"]("+o.data.url+")":"IMAGE"===o.type?"!("+o.data.src+")":"EMBEDDED_LINK"===o.type?'<iframe width="'+o.data.width+'" height="'+o.data.height+'" src="'+o.data.src+'" frameBorder="0" allowFullScreen />':n}function i(t,e){var n=[];if(e)for(var r=0,o=0,u=t,i=e.trigger||"#",a=e.separator||" ";u.length>0&&o>=0;)if(u[0]===i?(o=0,r=0,u=u.substr(i.length)):(o=u.indexOf(a+i),o>=0&&(u=u.substr(o+(a+i).length),r+=o+a.length)),o>=0){var s=u.indexOf(a)>=0?u.indexOf(a):u.length,f=u.substr(0,s);f&&f.length>0&&n.push({offset:r,length:f.length+i.length,type:"HASHTAG"}),r+=i.length}return n}function a(t,e){var n=[],r=0,o=t.entityRanges.map(function(t){var e=t.offset,n=t.length,r=t.key;return{offset:e,length:n,key:r,type:"ENTITY"}});return o=o.concat(i(t.text,e)),o=o.sort(function(t,e){return t.offset-e.offset}),o.forEach(function(t){t.offset>r&&n.push({start:r,end:t.offset-1}),n.push({start:t.offset,end:t.offset+t.length,entityKey:t.key,type:t.type}),r=t.offset+t.length}),r<t.text.length&&n.push({start:r,end:t.text.length}),n}function s(t){var e=t.text,n=t.inlineStyleRanges,r={COLOR:new Array(e.length),BGCOLOR:new Array(e.length),FONTSIZE:new Array(e.length),FONTFAMILY:new Array(e.length),SUBSCRIPT:new Array(e.length),SUPERSCRIPT:new Array(e.length),CODE:new Array(e.length),STRIKETHROUGH:new Array(e.length),UNDERLINE:new Array(e.length),ITALIC:new Array(e.length),BOLD: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,o=e;o<n;o+=1)t.style.startsWith("color-")?r.COLOR[o]=t.style.substring(6):t.style.startsWith("bgcolor-")?r.BGCOLOR[o]=t.style.substring(8):t.style.startsWith("fontsize-")?r.FONTSIZE[o]=t.style.substring(9):t.style.startsWith("fontfamily-")?r.FONTFAMILY[o]=t.style.substring(11):r[t.style]&&(r[t.style][o]=!0)}),r}function f(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 l(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.SUBSCRIPT[e]&&(n.SUBSCRIPT=!0),t.SUPERSCRIPT[e]&&(n.SUPERSCRIPT=!0),t.CODE[e]&&(n.CODE=!0),t.STRIKETHROUGH[e]&&(n.STRIKETHROUGH=!0),t.UNDERLINE[e]&&(n.UNDERLINE=!0),t.ITALIC[e]&&(n.ITALIC=!0),t.BOLD[e]&&(n.BOLD=!0),n}function c(t,e,n,r){var o=[],u=t.text;if(u.length>0)for(var i=s(t),a=void 0,c=n;c<r;c+=1)c!==n&&f(i,e,c)?(a.text.push(u[c]),a.end=c+1):(a={styles:l(i,c),text:[u[c]],start:c,end:c+1},o.push(a));return o}function h(t){if(t&&t.length>0){var e=t.map(function(t){switch(t){case"\n":return"\\s\\s\n";case"&":return"&";case"<":return"<";case">":return">";default:return t}});return e.join("")}return""}function O(t,e){return"BOLD"===t?"**"+e+"**":"ITALIC"===t?"*"+e+"*":"UNDERLINE"===t?"__"+e+"__":"STRIKETHROUGH"===t?"~~"+e+"~~":"CODE"===t?"`"+e+"`":"SUPERSCRIPT"===t?"<sup>"+e+"</sup>":"SUBSCRIPT"===t?"<sub>"+e+"</sub>":e}function y(t,e){var n=e;return(0,C.forEach)(t,function(t,e){n=O(t,n,e)}),n}function g(t){var e=t.styles,n=t.text,r=h(n);if(e&&(e.COLOR||e.BGCOLOR||e.FONTSIZE||e.FONTFAMILY)){var o='style="';return e.COLOR&&(o+="color: "+e.COLOR+";"),e.BGCOLOR&&(o+="background-color: "+e.BGCOLOR+";"),e.FONTSIZE&&(o+="font-size: "+e.FONTSIZE+"px;"),e.FONTFAMILY&&(o+="font-family: "+e.FONTFAMILY+";"),o+='"',"<span "+o+">"+r+"</span>"}return r}function d(t,e,n,r){var o=[],i=c(t,["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"],n.start,n.end),a="";i.forEach(function(e){var n=c(t,["COLOR","BGCOLOR","FONTSIZE","FONTFAMILY"],e.start,e.end),r="";n.forEach(function(t){r+=g(t)}),a+=y(e.styles,r)}),o.push(a);var s=o.join("");return"ENTITY"===n.type?void 0!==n.entityKey&&null!==n.entityKey&&(s=u(e,n.entityKey,s,r)):"HASHTAG"===n.type&&(s="["+s+"]("+s+")"),s}function p(t){if(t){for(var e=t,n=0;n<e.length&&" "===t[n];n+=1)e=e.replace(" "," ");return e}return t}function I(t){if(t){for(var e=t,n=e.length-1;n>=0&&" "===e[n];n-=1)e=e.substring(0,n)+" "+e.substring(n+1);return e}return t}function E(t,e,n,r){if(o(t))return u(e,t.entityRanges[0].key,void 0,r);var i=[],s=a(t,n);return s.forEach(function(n,r){var o=d(t,e,n);0===r&&(o=p(o)),r===s.length-1&&(o=I(o)),i.push(o)}),i.join("")}function R(t){var e="";return(0,C.forEach)(t,function(t,n){e+=t+":"+n+";"}),e}function T(t,e){var n=R(t);return n?'<span style="'+n+'">'+e+"</span>":e}function L(t,e,n,o){var u=[];u.push(r(t));var i=E(t,e,n,o);return t.data&&(i=T(t.data,i)),u.push(i),u.push("\n"),u.join("")}function S(t){for(var e="",n=0;n<4*t;n+=1)e+=" ";return e}function v(t,e,n){var r=[];return t&&!function(){var o=t.blocks,u=t.entityMap;o&&o.length>0&&o.forEach(function(t){var o=L(t,u,e,n);(0,C.isList)(t.type)&&(o=S(t.depth)+o),r.push(o)})}(),r.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.getBlockTagSymbol=r,e.sameStyleAsPrevious=f,e.getStylesAtOffset=l,e.addInlineStyleMarkdown=O,e.addStylePropertyMarkdown=g,e.trimLeadingZeros=p,e.trimTrailingZeros=I,e.getBlockContentMarkdown=E,e.getBlockStyle=R,e.default=v;var C=n(1),N={unstyled:"","header-one":"# ","header-two":"## ","header-three":"### ","header-four":"#### ","header-five":"##### ","header-six":"###### ","unordered-list-item":"- ","ordered-list-item":"1. ",blockquote:"> "}},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 o(t){return void 0===t||null===t||0===t.length||0===t.trim().length}function u(t){return"unordered-list-item"===t||"ordered-list-item"===t}Object.defineProperty(e,"__esModule",{value:!0}),e.forEach=r,e.isEmptyString=o,e.isList=u},function(t,e,n){t.exports=n(0)}]); | ||
module.exports=function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.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=2)}([function(t,e,n){"use strict";function r(t){return t.type&&N[t.type]}function o(t){return!!(t.entityRanges.length>0&&(0,C.isEmptyString)(t.text))}function u(t,e,n,r){var o=t[e];if("function"==typeof r){var u=r(o,n);if(u)return u}return"MENTION"===o.type?"["+n+"]("+o.data.url+")":"LINK"===o.type?"["+o.data.title+"]("+o.data.url+")":"IMAGE"===o.type?"!("+o.data.src+")":"EMBEDDED_LINK"===o.type?'<iframe width="'+o.data.width+'" height="'+o.data.height+'" src="'+o.data.src+'" frameBorder="0" allowFullScreen />':n}function i(t,e){var n=[];if(e)for(var r=0,o=0,u=t,i=e.trigger||"#",a=e.separator||" ";u.length>0&&o>=0;)if(u[0]===i?(o=0,r=0,u=u.substr(i.length)):(o=u.indexOf(a+i),o>=0&&(u=u.substr(o+(a+i).length),r+=o+a.length)),o>=0){var s=u.indexOf(a)>=0?u.indexOf(a):u.length,f=u.substr(0,s);f&&f.length>0&&n.push({offset:r,length:f.length+i.length,type:"HASHTAG"}),r+=i.length}return n}function a(t,e){var n=[],r=0,o=t.entityRanges.map(function(t){var e=t.offset,n=t.length,r=t.key;return{offset:e,length:n,key:r,type:"ENTITY"}});return o=o.concat(i(t.text,e)),o=o.sort(function(t,e){return t.offset-e.offset}),o.forEach(function(t){t.offset>r&&n.push({start:r,end:t.offset-1}),n.push({start:t.offset,end:t.offset+t.length,entityKey:t.key,type:t.type}),r=t.offset+t.length}),r<t.text.length&&n.push({start:r,end:t.text.length}),n}function s(t){var e=t.text,n=t.inlineStyleRanges,r={COLOR:new Array(e.length),BGCOLOR:new Array(e.length),FONTSIZE:new Array(e.length),FONTFAMILY:new Array(e.length),SUBSCRIPT:new Array(e.length),SUPERSCRIPT:new Array(e.length),CODE:new Array(e.length),STRIKETHROUGH:new Array(e.length),UNDERLINE:new Array(e.length),ITALIC:new Array(e.length),BOLD: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,o=e;o<n;o+=1)0===t.style.indexOf("color-")?r.COLOR[o]=t.style.substring(6):0===t.style.indexOf("bgcolor-")?r.BGCOLOR[o]=t.style.substring(8):0===t.style.indexOf("fontsize-")?r.FONTSIZE[o]=t.style.substring(9):0===t.style.indexOf("fontfamily-")?r.FONTFAMILY[o]=t.style.substring(11):r[t.style]&&(r[t.style][o]=!0)}),r}function f(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 l(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.SUBSCRIPT[e]&&(n.SUBSCRIPT=!0),t.SUPERSCRIPT[e]&&(n.SUPERSCRIPT=!0),t.CODE[e]&&(n.CODE=!0),t.STRIKETHROUGH[e]&&(n.STRIKETHROUGH=!0),t.UNDERLINE[e]&&(n.UNDERLINE=!0),t.ITALIC[e]&&(n.ITALIC=!0),t.BOLD[e]&&(n.BOLD=!0),n}function c(t,e,n,r){var o=[],u=t.text;if(u.length>0)for(var i=s(t),a=void 0,c=n;c<r;c+=1)c!==n&&f(i,e,c)?(a.text.push(u[c]),a.end=c+1):(a={styles:l(i,c),text:[u[c]],start:c,end:c+1},o.push(a));return o}function O(t){if(t&&t.length>0){var e=t.map(function(t){switch(t){case"\n":return"\\s\\s\n";case"&":return"&";case"<":return"<";case">":return">";default:return t}});return e.join("")}return""}function h(t,e){return"BOLD"===t?"**"+e+"**":"ITALIC"===t?"*"+e+"*":"UNDERLINE"===t?"__"+e+"__":"STRIKETHROUGH"===t?"~~"+e+"~~":"CODE"===t?"`"+e+"`":"SUPERSCRIPT"===t?"<sup>"+e+"</sup>":"SUBSCRIPT"===t?"<sub>"+e+"</sub>":e}function y(t,e){var n=e;return(0,C.forEach)(t,function(t,e){n=h(t,n,e)}),n}function g(t){var e=t.styles,n=t.text,r=O(n);if(e&&(e.COLOR||e.BGCOLOR||e.FONTSIZE||e.FONTFAMILY)){var o='style="';return e.COLOR&&(o+="color: "+e.COLOR+";"),e.BGCOLOR&&(o+="background-color: "+e.BGCOLOR+";"),e.FONTSIZE&&(o+="font-size: "+e.FONTSIZE+"px;"),e.FONTFAMILY&&(o+="font-family: "+e.FONTFAMILY+";"),o+='"',"<span "+o+">"+r+"</span>"}return r}function d(t,e,n,r){var o=[],i=c(t,["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"],n.start,n.end),a="";i.forEach(function(e){var n=c(t,["COLOR","BGCOLOR","FONTSIZE","FONTFAMILY"],e.start,e.end),r="";n.forEach(function(t){r+=g(t)}),a+=y(e.styles,r)}),o.push(a);var s=o.join("");return"ENTITY"===n.type?void 0!==n.entityKey&&null!==n.entityKey&&(s=u(e,n.entityKey,s,r)):"HASHTAG"===n.type&&(s="["+s+"]("+s+")"),s}function p(t){if(t){for(var e=t,n=0;n<e.length&&" "===t[n];n+=1)e=e.replace(" "," ");return e}return t}function I(t){if(t){for(var e=t,n=e.length-1;n>=0&&" "===e[n];n-=1)e=e.substring(0,n)+" "+e.substring(n+1);return e}return t}function E(t,e,n,r){if(o(t))return u(e,t.entityRanges[0].key,void 0,r);var i=[],s=a(t,n);return s.forEach(function(n,r){var o=d(t,e,n);0===r&&(o=p(o)),r===s.length-1&&(o=I(o)),i.push(o)}),i.join("")}function R(t){var e="";return(0,C.forEach)(t,function(t,n){e+=t+":"+n+";"}),e}function T(t,e){var n=R(t);return n?'<span style="'+n+'">'+e+"</span>":e}function L(t,e,n,o){var u=[];u.push(r(t));var i=E(t,e,n,o);return t.data&&(i=T(t.data,i)),u.push(i),u.push("\n"),u.join("")}function S(t){for(var e="",n=0;n<4*t;n+=1)e+=" ";return e}function v(t,e,n){var r=[];return t&&!function(){var o=t.blocks,u=t.entityMap;o&&o.length>0&&o.forEach(function(t){var o=L(t,u,e,n);(0,C.isList)(t.type)&&(o=S(t.depth)+o),r.push(o)})}(),r.join("")}Object.defineProperty(e,"__esModule",{value:!0}),e.getBlockTagSymbol=r,e.sameStyleAsPrevious=f,e.getStylesAtOffset=l,e.addInlineStyleMarkdown=h,e.addStylePropertyMarkdown=g,e.trimLeadingZeros=p,e.trimTrailingZeros=I,e.getBlockContentMarkdown=E,e.getBlockStyle=R,e.default=v;var C=n(1),N={unstyled:"","header-one":"# ","header-two":"## ","header-three":"### ","header-four":"#### ","header-five":"##### ","header-six":"###### ","unordered-list-item":"- ","ordered-list-item":"1. ",blockquote:"> "}},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 o(t){return void 0===t||null===t||0===t.length||0===t.trim().length}function u(t){return"unordered-list-item"===t||"ordered-list-item"===t}Object.defineProperty(e,"__esModule",{value:!0}),e.forEach=r,e.isEmptyString=o,e.isList=u},function(t,e,n){t.exports=n(0)}]); |
{ | ||
"name": "draftjs-to-markdown", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "A library for draftjs to markdown conversion.", | ||
@@ -5,0 +5,0 @@ "main": "lib/draftjs-to-markdown.js", |
@@ -20,3 +20,5 @@ # DraftJS TO Markdown | ||
The function parameters are: | ||
1. **contentState**: Its instance of [RawDraftContentState](https://facebook.github.io/draft-js/docs/api-reference-data-conversion.html#content) | ||
2. **hashConfig**: Its configuration object for hashtag, its required only if hashtags are used. If the object is not defined hashtags will be output as simple text in the markdown. | ||
@@ -23,0 +25,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143094
78