forked from pavittarx/editorjs-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edjsHTML.node.js
1 lines (1 loc) · 2.13 KB
/
edjsHTML.node.js
1
"use strict";var t=["left","right","center","justify"],n={delimiter:function(){return"<br/>"},header:function(t){var n=t.data;return"<h".concat(n.level,">").concat(n.text,"</h").concat(n.level,">")},paragraph:function(n){var e=n.data,r=e.alignment||e.align;return void 0!==r&&t.includes(r)?'<p style="text-align:'.concat(r,';">').concat(e.text,"</p>"):"<p>".concat(e.text,"</p>")},list:function(t){var n=t.data,e="unordered"===n.style?"ul":"ol",r=function(t,n){var e=t.map((function(t){if(!t.content&&!t.items)return"<li>".concat(t,"</li>");var e="";return t.items&&(e=r(t.items,n)),t.content?"<li> ".concat(t.content," ").concat(e," </li>"):void 0}));return"<".concat(n,">").concat(e.join(""),"</").concat(n,">")};return r(n.items,e)},image:function(t){var n=t.data,e=n.caption?n.caption:"Image";return'<img src="'.concat(n.file&&n.file.url?n.file.url:n.url,'" alt="').concat(e,'" />')},quote:function(t){var n=t.data;return"<blockquote>".concat(n.text,"</blockquote> - ").concat(n.caption)},code:function(t){var n=t.data;return"<pre><code>".concat(n.code,"</code></pre>")},embed:function(t){var n=t.data;return'<iframe width="'.concat(n.width,'" height="').concat(n.height,'" frameborder="0" src="').concat(n.embed,'" allowfullscreen></iframe>')}};function e(t){return new Error('[31m The Parser function of type "'.concat(t,'" is not defined. \n\n Define your custom parser functions as: [34mhttps://github.com/pavittarx/editorjs-html#extend-for-custom-blocks [0m'))}var r=function(t){void 0===t&&(t={});var c=Object.assign({},n,t);return{parse:function(t){return t.blocks.map((function(t){return c[t.type]?c[t.type](t):e(t.type)}))},parseBlock:function(t){return c[t.type]?c[t.type](t):e(t.type)},parseStrict:function(t){var n=t.blocks,o=r(c).validate({blocks:n});if(o.length)throw new Error("Parser Functions missing for blocks: ".concat(o.toString()));for(var a=[],i=0;i<n.length;i++){if(!c[n[i].type])throw e(n[i].type);a.push(c[n[i].type](n[i]))}return a},validate:function(t){var n=t.blocks.map((function(t){return t.type})).filter((function(t,n,e){return e.indexOf(t)===n})),e=Object.keys(c);return n.filter((function(t){return!e.includes(t)}))}}};module.exports=r;