@sanity/block-content-to-html
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -19,2 +19,6 @@ 'use strict'; | ||
var _escapeHtml2 = require('./escapeHtml'); | ||
var _escapeHtml3 = _interopRequireDefault(_escapeHtml2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -37,3 +41,3 @@ | ||
value: function escapeHtml(unsafe) { | ||
return (0, _typeHandlers.escapeHtml)(unsafe); | ||
return (0, _escapeHtml3.default)(unsafe); | ||
} | ||
@@ -40,0 +44,0 @@ }]); |
@@ -9,4 +9,2 @@ 'use strict'; | ||
exports.escapeHTML = escapeHTML; | ||
exports.default = function () { | ||
@@ -75,6 +73,8 @@ var blockTypeHandlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
function escapeHTML(unsafe) { | ||
return unsafe.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/'); | ||
} | ||
var _escapeHtml = require('./escapeHtml'); | ||
var _escapeHtml2 = _interopRequireDefault(_escapeHtml); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getContent(content, typeHandlers) { | ||
@@ -84,3 +84,3 @@ var output = ''; | ||
if (typeof item === 'string') { | ||
output += escapeHTML(item); | ||
output += (0, _escapeHtml2.default)(item); | ||
} else { | ||
@@ -98,3 +98,3 @@ var handler = typeHandlers[item.type] || typeHandlers.text; | ||
if (typeof item === 'string') { | ||
output += escapeHTML(item); | ||
output += (0, _escapeHtml2.default)(item); | ||
} else { | ||
@@ -101,0 +101,0 @@ var contentHandler = typeHandlers[item.type] || typeHandlers.textBlock; |
{ | ||
"name": "@sanity/block-content-to-html", | ||
"description": "Customizable HTML parser for block editor output", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "umd": "umd/index.min.js", |
@@ -224,2 +224,11 @@ /* eslint-disable id-length */ | ||
test('exposes the escapeHtml utility function', {todo: false}, t => { | ||
const input = '<foo>' | ||
const expected = '<foo>' | ||
const got = BlockContentToHtml.escapeHtml(input) | ||
t.same(got, expected) | ||
t.end() | ||
}) | ||
/* eslint-enable id-length */ |
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BlockContentAdapter = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function parseSingle(e,t){if(t[e.type])return t[e.type](e);throw new Error("Don't know how to handle type '"+e.type+"'")}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),_blockContentToTree=require("@sanity/block-content-to-tree"),_blockContentToTree2=_interopRequireDefault(_blockContentToTree),_typeHandlers=require("./type-handlers"),_typeHandlers2=_interopRequireDefault(_typeHandlers),baseAdapter=new _blockContentToTree2.default,BlockContentToHtml=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,e);var n=t.customTypeHandlers||{};this.typeHandlers=_extends({},(0,_typeHandlers2.default)(t.blockTypeHandlers||{}),n)}return _createClass(e,null,[{key:"escapeHtml",value:function(e){return(0,_typeHandlers.escapeHtml)(e)}}]),_createClass(e,[{key:"convert",value:function(e){var t=this,n=baseAdapter.parse(e);return Array.isArray(n)?n.map(function(e){return parseSingle(e,t.typeHandlers)}).join("\n"):parseSingle(n,this.typeHandlers)}}]),e}();exports.default=BlockContentToHtml; | ||
},{"./type-handlers":3,"@sanity/block-content-to-tree":6}],2:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function parseSingle(e,t){if(t[e.type])return t[e.type](e);throw new Error("Don't know how to handle type '"+e.type+"'")}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_blockContentToTree=require("@sanity/block-content-to-tree"),_blockContentToTree2=_interopRequireDefault(_blockContentToTree),_typeHandlers=require("./type-handlers"),_typeHandlers2=_interopRequireDefault(_typeHandlers),_escapeHtml2=require("./escapeHtml"),_escapeHtml3=_interopRequireDefault(_escapeHtml2),baseAdapter=new _blockContentToTree2.default,BlockContentToHtml=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,e);var r=t.customTypeHandlers||{};this.typeHandlers=_extends({},(0,_typeHandlers2.default)(t.blockTypeHandlers||{}),r)}return _createClass(e,null,[{key:"escapeHtml",value:function(e){return(0,_escapeHtml3.default)(e)}}]),_createClass(e,[{key:"convert",value:function(e){var t=this,r=baseAdapter.parse(e);return Array.isArray(r)?r.map(function(e){return parseSingle(e,t.typeHandlers)}).join("\n"):parseSingle(r,this.typeHandlers)}}]),e}();exports.default=BlockContentToHtml; | ||
},{"./escapeHtml":2,"./type-handlers":4,"@sanity/block-content-to-tree":7}],2:[function(require,module,exports){ | ||
"use strict";function escapeHTML(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=escapeHTML; | ||
},{}],3:[function(require,module,exports){ | ||
"use strict";module.exports=require("./BlockContentToHtml.js"); | ||
},{"./BlockContentToHtml.js":1}],3:[function(require,module,exports){ | ||
"use strict";function escapeHTML(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}function getContent(t,e){var n="";return t.forEach(function(t){if("string"==typeof t)n+=escapeHTML(t);else{var r=e[t.type]||e.text;n+=r(t)}}),n}function getListItems(t,e,n){var r="";return t.forEach(function(t){if("string"==typeof t)r+=escapeHTML(t);else{var i=n[t.type]||n.textBlock;t.children=i(t),r+=e.listItem(t)}}),r}function mapMark(t,e){return e&&void 0!==e[t]?e[t]:t}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t};exports.escapeHTML=escapeHTML,exports.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=_extends({normal:function(t){return"<p>"+t.children+"</p>"}},t.textBlock||{}),n=_extends({number:function(t){return"<ol>"+t.children+"</ol>"},bullet:function(t){return"<ul>"+t.children+"</ul>"},listItem:function(t){return"<li>"+t.children+"</li>"}},t.listBlock||{}),r={block:function(t){return e[t.style]?(t.children=getContent(t.content,r),e[t.style](t)):"<"+t.style+">"+getContent(t.content,r)+"</"+t.style+">"},list:function(t){return n[t.itemStyle]?(t.children=getListItems(t.items,n,r),n[t.itemStyle](t)):"<ul>"+getListItems(t.items,n,r)+"</ul>"},span:function(e){var n="",i="";if(e.mark){var l=mapMark(e.mark,t.marks);n+=l?"<"+l+">":"",i=l?"</"+l+">":""}return e.children=getContent(e.content,r),t.span?""+n+t.span(e)+i:(e.attributes&&e.attributes.link&&(n+='<a href="'+e.attributes.link.href+'">',i="</a>"+i),""+n+getContent(e.content,r)+i)}};return r}; | ||
},{}],4:[function(require,module,exports){ | ||
},{"./BlockContentToHtml.js":1}],4:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function getContent(t,e){var n="";return t.forEach(function(t){if("string"==typeof t)n+=(0,_escapeHtml2.default)(t);else{var r=e[t.type]||e.text;n+=r(t)}}),n}function getListItems(t,e,n){var r="";return t.forEach(function(t){if("string"==typeof t)r+=(0,_escapeHtml2.default)(t);else{var i=n[t.type]||n.textBlock;t.children=i(t),r+=e.listItem(t)}}),r}function mapMark(t,e){return e&&void 0!==e[t]?e[t]:t}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t};exports.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=_extends({normal:function(t){return"<p>"+t.children+"</p>"}},t.textBlock||{}),n=_extends({number:function(t){return"<ol>"+t.children+"</ol>"},bullet:function(t){return"<ul>"+t.children+"</ul>"},listItem:function(t){return"<li>"+t.children+"</li>"}},t.listBlock||{}),r={block:function(t){return e[t.style]?(t.children=getContent(t.content,r),e[t.style](t)):"<"+t.style+">"+getContent(t.content,r)+"</"+t.style+">"},list:function(t){return n[t.itemStyle]?(t.children=getListItems(t.items,n,r),n[t.itemStyle](t)):"<ul>"+getListItems(t.items,n,r)+"</ul>"},span:function(e){var n="",i="";if(e.mark){var l=mapMark(e.mark,t.marks);n+=l?"<"+l+">":"",i=l?"</"+l+">":""}return e.children=getContent(e.content,r),t.span?""+n+t.span(e)+i:(e.attributes&&e.attributes.link&&(n+='<a href="'+e.attributes.link.href+'">',i="</a>"+i),""+n+getContent(e.content,r)+i)}};return r};var _escapeHtml=require("./escapeHtml"),_escapeHtml2=_interopRequireDefault(_escapeHtml); | ||
},{"./escapeHtml":2}],5:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},_createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),_typeHandlers=require("./type-handlers"),_typeHandlers2=_interopRequireDefault(_typeHandlers),_typeCheckers=require("./type-checkers"),Adapter=function(){function e(){_classCallCheck(this,e),this.typeHandlers=_typeHandlers2.default}return _createClass(e,[{key:"parse",value:function(e){var r=this;if(Array.isArray(e)){var t=[],n=[];return e.forEach(function(e,a,s){if((0,_typeCheckers.isList)(e)){n.push(e);if((s[a+1]||{}).listItem!==e.listItem){var i=Array.from(n);n=[],t.push(r.parseListBlocks(i))}}else t.push(r.parseSingleBlock(e))}),t}if(!e||!e._type)throw new Error("Input must be an Array or an Object (with a ._type) - got "+e);return this.parseSingleBlock(e)}},{key:"parseListBlocks",value:function(e){return this.typeHandlers.list(e)}},{key:"parseSingleBlock",value:function(e){var r=e._type,t=this.typeHandlers[r];if(!t){var n=_extends({},e);return delete n._type,{type:r,attributes:n}}return t(e)}}]),e}();exports.default=Adapter; | ||
},{"./type-checkers":7,"./type-handlers":8}],5:[function(require,module,exports){ | ||
},{"./type-checkers":8,"./type-handlers":9}],6:[function(require,module,exports){ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),ContentNester=function(){function e(t){_classCallCheck(this,e),this.spans=t}return _createClass(e,[{key:"run",value:function(){var e={content:[]},t=[e];return this.spans.forEach(function(e){var n=_extends({},e);delete n.text,delete n.marks,delete n._type;var r=e.marks.sort(),a=1;if(t.length>1)for(a;a<t.length;a++){var s=t[a].mark;if(!r.includes(s))break;var o=r.indexOf(s);r.splice(o,1)}t=t.slice(0,a);var c=t.slice(-1)[0];r.forEach(function(e){var n={content:[],mark:e,type:"span",attributes:{}};c.content.push(n),t.push(n),c=n}),Object.keys(n).length?c.content.push({type:"span",attributes:n,content:[e.text]}):c.content.push(e.text)}),e.content}}]),e}(),getContent=function(e){return new ContentNester(e).run()};exports.default=getContent; | ||
},{}],6:[function(require,module,exports){ | ||
},{}],7:[function(require,module,exports){ | ||
"use strict";module.exports=require("./Adapter.js"); | ||
},{"./Adapter.js":4}],7:[function(require,module,exports){ | ||
},{"./Adapter.js":5}],8:[function(require,module,exports){ | ||
"use strict";function isList(t){var e=t._type,s=t.listItem;return"block"===e&&!!s}function isText(t){return"block"===t._type&&!isList(t)}function getInternalBlockType(t){return isText(t)?"text":isList(t)?"list":"custom"}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isList=isList,exports.isText=isText,exports.getInternalBlockType=getInternalBlockType; | ||
},{}],9:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _ContentNester=require("./ContentNester"),_ContentNester2=_interopRequireDefault(_ContentNester),block=function(e){return{type:"block",style:e.style,content:(0,_ContentNester2.default)(e.spans)}},list=function(e){return{type:"list",itemStyle:e[0].listItem,items:e.map(function(e){return{type:"block",style:e.style,content:(0,_ContentNester2.default)(e.spans)}})}};exports.default={block:block,list:list}; | ||
},{}],8:[function(require,module,exports){ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _ContentNester=require("./ContentNester"),_ContentNester2=_interopRequireDefault(_ContentNester),block=function(e){return{type:"block",style:e.style,content:(0,_ContentNester2.default)(e.spans)}},list=function(e){return{type:"list",itemStyle:e[0].listItem,items:e.map(function(e){return{type:"block",style:e.style,content:(0,_ContentNester2.default)(e.spans)}})}};exports.default={block:block,list:list}; | ||
},{"./ContentNester":5}]},{},[2])(2) | ||
},{"./ContentNester":6}]},{},[3])(3) | ||
}); |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.BlockContentAdapter=e()}}(function(){return function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var l="function"==typeof require&&require;if(!a&&l)return l(u,!0);if(i)return i(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n||e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(t[e.type])return t[e.type](e);throw new Error("Don't know how to handle type '"+e.type+"'")}Object.defineProperty(n,"__esModule",{value:!0});var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),l=e("@sanity/block-content-to-tree"),c=r(l),s=e("./type-handlers"),f=r(s),p=new c.default,y=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e);var n=t.customTypeHandlers||{};this.typeHandlers=u({},(0,f.default)(t.blockTypeHandlers||{}),n)}return a(e,null,[{key:"escapeHtml",value:function(e){return(0,s.escapeHtml)(e)}}]),a(e,[{key:"convert",value:function(e){var t=this,n=p.parse(e);return Array.isArray(n)?n.map(function(e){return i(e,t.typeHandlers)}).join("\n"):i(n,this.typeHandlers)}}]),e}();n.default=y},{"./type-handlers":3,"@sanity/block-content-to-tree":6}],2:[function(e,t,n){"use strict";t.exports=e("./BlockContentToHtml.js")},{"./BlockContentToHtml.js":1}],3:[function(e,t,n){"use strict";function r(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}function o(e,t){var n="";return e.forEach(function(e){if("string"==typeof e)n+=r(e);else{var o=t[e.type]||t.text;n+=o(e)}}),n}function i(e,t,n){var o="";return e.forEach(function(e){if("string"==typeof e)o+=r(e);else{var i=n[e.type]||n.textBlock;e.children=i(e),o+=t.listItem(e)}}),o}function u(e,t){return t&&void 0!==t[e]?t[e]:e}Object.defineProperty(n,"__esModule",{value:!0});var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};n.escapeHTML=r,n.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=a({normal:function(e){return"<p>"+e.children+"</p>"}},e.textBlock||{}),n=a({number:function(e){return"<ol>"+e.children+"</ol>"},bullet:function(e){return"<ul>"+e.children+"</ul>"},listItem:function(e){return"<li>"+e.children+"</li>"}},e.listBlock||{}),r={block:function(e){return t[e.style]?(e.children=o(e.content,r),t[e.style](e)):"<"+e.style+">"+o(e.content,r)+"</"+e.style+">"},list:function(e){return n[e.itemStyle]?(e.children=i(e.items,n,r),n[e.itemStyle](e)):"<ul>"+i(e.items,n,r)+"</ul>"},span:function(t){var n="",i="";if(t.mark){var a=u(t.mark,e.marks);n+=a?"<"+a+">":"",i=a?"</"+a+">":""}return t.children=o(t.content,r),e.span?""+n+e.span(t)+i:(t.attributes&&t.attributes.link&&(n+='<a href="'+t.attributes.link.href+'">',i="</a>"+i),""+n+o(t.content,r)+i)}};return r}},{}],4:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=e("./type-handlers"),a=function(e){return e&&e.__esModule?e:{default:e}}(u),l=e("./type-checkers"),c=function(){function e(){r(this,e),this.typeHandlers=a.default}return i(e,[{key:"parse",value:function(e){var t=this;if(Array.isArray(e)){var n=[],r=[];return e.forEach(function(e,o,i){if((0,l.isList)(e)){if(r.push(e),(i[o+1]||{}).listItem!==e.listItem){var u=Array.from(r);r=[],n.push(t.parseListBlocks(u))}}else n.push(t.parseSingleBlock(e))}),n}if(!e||!e._type)throw new Error("Input must be an Array or an Object (with a ._type) - got "+e);return this.parseSingleBlock(e)}},{key:"parseListBlocks",value:function(e){return this.typeHandlers.list(e)}},{key:"parseSingleBlock",value:function(e){var t=e._type,n=this.typeHandlers[t];if(!n){var r=o({},e);return delete r._type,{type:t,attributes:r}}return n(e)}}]),e}();n.default=c},{"./type-checkers":7,"./type-handlers":8}],5:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=function(){function e(t){r(this,e),this.spans=t}return i(e,[{key:"run",value:function(){var e={content:[]},t=[e];return this.spans.forEach(function(e){var n=o({},e);delete n.text,delete n.marks,delete n._type;var r=e.marks.sort(),i=1;if(t.length>1)for(i;i<t.length;i++){var u=t[i].mark;if(!r.includes(u))break;var a=r.indexOf(u);r.splice(a,1)}t=t.slice(0,i);var l=t.slice(-1)[0];r.forEach(function(e){var n={content:[],mark:e,type:"span",attributes:{}};l.content.push(n),t.push(n),l=n}),Object.keys(n).length?l.content.push({type:"span",attributes:n,content:[e.text]}):l.content.push(e.text)}),e.content}}]),e}(),a=function(e){return new u(e).run()};n.default=a},{}],6:[function(e,t,n){"use strict";t.exports=e("./Adapter.js")},{"./Adapter.js":4}],7:[function(e,t,n){"use strict";function r(e){var t=e._type,n=e.listItem;return"block"===t&&!!n}function o(e){return"block"===e._type&&!r(e)}function i(e){return o(e)?"text":r(e)?"list":"custom"}Object.defineProperty(n,"__esModule",{value:!0}),n.isList=r,n.isText=o,n.getInternalBlockType=i},{}],8:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./ContentNester"),o=function(e){return e&&e.__esModule?e:{default:e}}(r),i=function(e){return{type:"block",style:e.style,content:(0,o.default)(e.spans)}},u=function(e){return{type:"list",itemStyle:e[0].listItem,items:e.map(function(e){return{type:"block",style:e.style,content:(0,o.default)(e.spans)}})}};n.default={block:i,list:u}},{"./ContentNester":5}]},{},[2])(2)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.BlockContentAdapter=e()}}(function(){return function e(t,n,r){function o(i,a){if(!n[i]){if(!t[i]){var l="function"==typeof require&&require;if(!a&&l)return l(i,!0);if(u)return u(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var s=n[i]={exports:{}};t[i][0].call(s.exports,function(e){var n=t[i][1][e];return o(n||e)},s,s.exports,e,t,n,r)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(t[e.type])return t[e.type](e);throw new Error("Don't know how to handle type '"+e.type+"'")}Object.defineProperty(n,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),l=e("@sanity/block-content-to-tree"),c=r(l),s=e("./type-handlers"),f=r(s),p=e("./escapeHtml"),y=r(p),d=new c.default,v=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e);var n=t.customTypeHandlers||{};this.typeHandlers=i({},(0,f.default)(t.blockTypeHandlers||{}),n)}return a(e,null,[{key:"escapeHtml",value:function(e){return(0,y.default)(e)}}]),a(e,[{key:"convert",value:function(e){var t=this,n=d.parse(e);return Array.isArray(n)?n.map(function(e){return u(e,t.typeHandlers)}).join("\n"):u(n,this.typeHandlers)}}]),e}();n.default=v},{"./escapeHtml":2,"./type-handlers":4,"@sanity/block-content-to-tree":7}],2:[function(e,t,n){"use strict";function r(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}Object.defineProperty(n,"__esModule",{value:!0}),n.default=r},{}],3:[function(e,t,n){"use strict";t.exports=e("./BlockContentToHtml.js")},{"./BlockContentToHtml.js":1}],4:[function(e,t,n){"use strict";function r(e,t){var n="";return e.forEach(function(e){if("string"==typeof e)n+=(0,l.default)(e);else{var r=t[e.type]||t.text;n+=r(e)}}),n}function o(e,t,n){var r="";return e.forEach(function(e){if("string"==typeof e)r+=(0,l.default)(e);else{var o=n[e.type]||n.textBlock;e.children=o(e),r+=t.listItem(e)}}),r}function u(e,t){return t&&void 0!==t[e]?t[e]:e}Object.defineProperty(n,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};n.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=i({normal:function(e){return"<p>"+e.children+"</p>"}},e.textBlock||{}),n=i({number:function(e){return"<ol>"+e.children+"</ol>"},bullet:function(e){return"<ul>"+e.children+"</ul>"},listItem:function(e){return"<li>"+e.children+"</li>"}},e.listBlock||{}),a={block:function(e){return t[e.style]?(e.children=r(e.content,a),t[e.style](e)):"<"+e.style+">"+r(e.content,a)+"</"+e.style+">"},list:function(e){return n[e.itemStyle]?(e.children=o(e.items,n,a),n[e.itemStyle](e)):"<ul>"+o(e.items,n,a)+"</ul>"},span:function(t){var n="",o="";if(t.mark){var i=u(t.mark,e.marks);n+=i?"<"+i+">":"",o=i?"</"+i+">":""}return t.children=r(t.content,a),e.span?""+n+e.span(t)+o:(t.attributes&&t.attributes.link&&(n+='<a href="'+t.attributes.link.href+'">',o="</a>"+o),""+n+r(t.content,a)+o)}};return a};var a=e("./escapeHtml"),l=function(e){return e&&e.__esModule?e:{default:e}}(a)},{"./escapeHtml":2}],5:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=e("./type-handlers"),a=function(e){return e&&e.__esModule?e:{default:e}}(i),l=e("./type-checkers"),c=function(){function e(){r(this,e),this.typeHandlers=a.default}return u(e,[{key:"parse",value:function(e){var t=this;if(Array.isArray(e)){var n=[],r=[];return e.forEach(function(e,o,u){if((0,l.isList)(e)){if(r.push(e),(u[o+1]||{}).listItem!==e.listItem){var i=Array.from(r);r=[],n.push(t.parseListBlocks(i))}}else n.push(t.parseSingleBlock(e))}),n}if(!e||!e._type)throw new Error("Input must be an Array or an Object (with a ._type) - got "+e);return this.parseSingleBlock(e)}},{key:"parseListBlocks",value:function(e){return this.typeHandlers.list(e)}},{key:"parseSingleBlock",value:function(e){var t=e._type,n=this.typeHandlers[t];if(!n){var r=o({},e);return delete r._type,{type:t,attributes:r}}return n(e)}}]),e}();n.default=c},{"./type-checkers":8,"./type-handlers":9}],6:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function(){function e(t){r(this,e),this.spans=t}return u(e,[{key:"run",value:function(){var e={content:[]},t=[e];return this.spans.forEach(function(e){var n=o({},e);delete n.text,delete n.marks,delete n._type;var r=e.marks.sort(),u=1;if(t.length>1)for(u;u<t.length;u++){var i=t[u].mark;if(!r.includes(i))break;var a=r.indexOf(i);r.splice(a,1)}t=t.slice(0,u);var l=t.slice(-1)[0];r.forEach(function(e){var n={content:[],mark:e,type:"span",attributes:{}};l.content.push(n),t.push(n),l=n}),Object.keys(n).length?l.content.push({type:"span",attributes:n,content:[e.text]}):l.content.push(e.text)}),e.content}}]),e}(),a=function(e){return new i(e).run()};n.default=a},{}],7:[function(e,t,n){"use strict";t.exports=e("./Adapter.js")},{"./Adapter.js":5}],8:[function(e,t,n){"use strict";function r(e){var t=e._type,n=e.listItem;return"block"===t&&!!n}function o(e){return"block"===e._type&&!r(e)}function u(e){return o(e)?"text":r(e)?"list":"custom"}Object.defineProperty(n,"__esModule",{value:!0}),n.isList=r,n.isText=o,n.getInternalBlockType=u},{}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./ContentNester"),o=function(e){return e&&e.__esModule?e:{default:e}}(r),u=function(e){return{type:"block",style:e.style,content:(0,o.default)(e.spans)}},i=function(e){return{type:"list",itemStyle:e[0].listItem,items:e.map(function(e){return{type:"block",style:e.style,content:(0,o.default)(e.spans)}})}};n.default={block:u,list:i}},{"./ContentNester":6}]},{},[3])(3)}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
61843
34
1013