@sanity/block-content-to-html
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -54,4 +54,3 @@ 'use strict'; | ||
} | ||
// Fallback | ||
return this.typeHandlers.unhandledBlock(data); | ||
throw new Error('Don\'t know how to handle type \'' + data.type + '\''); | ||
} | ||
@@ -58,0 +57,0 @@ }]); |
@@ -9,4 +9,2 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.default = function () { | ||
@@ -69,13 +67,2 @@ var blockTypeHandlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return '' + head + getContent(node.content, typeHandlers) + tail; | ||
}, | ||
unhandledBlock: function unhandledBlock(node) { | ||
var result = ''; | ||
Object.keys(node.attributes).forEach(function (aKey) { | ||
// Output a comment with metainfo | ||
var primitive = isPrimitive(node.attributes[aKey]); | ||
var metaValue = primitive ? node.attributes[aKey] : JSON.stringify(node.attributes[aKey]).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); | ||
result += '<div data-unhandled-attribute-name="' + aKey + '" data-unhandled-attribute-value="' + metaValue + '" />'; | ||
}); | ||
return result; | ||
} | ||
@@ -87,5 +74,4 @@ }; | ||
function isPrimitive(val) { | ||
var type = typeof val === 'undefined' ? 'undefined' : _typeof(val); | ||
return val === null || type !== 'object' && type !== 'function'; | ||
function escapeHtml(unsafe) { | ||
return unsafe.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/'); | ||
} | ||
@@ -97,3 +83,3 @@ | ||
if (typeof item === 'string') { | ||
output += item; | ||
output += escapeHtml(item); | ||
} else { | ||
@@ -111,3 +97,3 @@ var handler = typeHandlers[item.type] || typeHandlers.text; | ||
if (typeof item === 'string') { | ||
output += item; | ||
output += escapeHtml(item); | ||
} else { | ||
@@ -114,0 +100,0 @@ var contentHandler = typeHandlers[item.type] || typeHandlers.textBlock; |
{ | ||
"name": "@sanity/block-content-to-html", | ||
"description": "Customizable HTML parser for block editor output", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "lib/index.js", | ||
@@ -25,3 +25,3 @@ "umd": "umd/index.min.js", | ||
"dependencies": { | ||
"@sanity/block-content-to-tree": "0.0.4", | ||
"@sanity/block-content-to-tree": "0.0.5", | ||
"in-publish": "^2.0.0" | ||
@@ -28,0 +28,0 @@ }, |
@@ -199,7 +199,7 @@ /* eslint-disable id-length */ | ||
test('handles a custom block type without a registered handler', {todo: false}, t => { | ||
test('throws an error on custom block type without a registered handler', {todo: false}, t => { | ||
const input = require('./fixtures/custom-block.json') | ||
const expected = '<div data-unhandled-attribute-name="name" data-unhandled-attribute-value="Test Person" />' | ||
const got = adapter.parse(input) | ||
t.same(got, expected) | ||
t.throws(() => { | ||
adapter.parse(input) | ||
}, {message: "Don't know how to handle type 'author'"}, {}) | ||
t.end() | ||
@@ -216,2 +216,11 @@ }) | ||
test('handles dangerous text', {todo: false}, t => { | ||
const input = require('./fixtures/dangerous-text.json') | ||
const expected = '<p>I am 1337 <script>alert('//haxxor');</script></p>' | ||
const got = adapter.parse(input) | ||
t.same(got, expected) | ||
t.end() | ||
}) | ||
/* eslint-enable id-length */ |
{ | ||
"_type": "author", | ||
"name": "Test Person" | ||
"name": "Test Person", | ||
"description": "<script>alert('I am haxor!');</script>" | ||
} |
(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")}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),baseAdapter=new _blockContentToTree2.default,Adapter=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,[{key:"parse",value:function(e){var t=this,r=baseAdapter.parse(e);return Array.isArray(r)?r.map(function(e){return t.parseSingle(e)}).join("\n"):this.parseSingle(r)}},{key:"parseSingle",value:function(e){return this.typeHandlers[e.type]?this.typeHandlers[e.type](e):this.typeHandlers.unhandledBlock(e)}}]),e}();exports.default=Adapter; | ||
"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")}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),baseAdapter=new _blockContentToTree2.default,Adapter=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,[{key:"parse",value:function(e){var t=this,r=baseAdapter.parse(e);return Array.isArray(r)?r.map(function(e){return t.parseSingle(e)}).join("\n"):this.parseSingle(r)}},{key:"parseSingle",value:function(e){if(this.typeHandlers[e.type])return this.typeHandlers[e.type](e);throw new Error("Don't know how to handle type '"+e.type+"'")}}]),e}();exports.default=Adapter; | ||
},{"./type-handlers":3,"@sanity/block-content-to-tree":6}],2:[function(require,module,exports){ | ||
"use strict";module.exports=require("./Adapter.js"); | ||
},{"./Adapter.js":1}],3:[function(require,module,exports){ | ||
"use strict";function isPrimitive(t){var e=void 0===t?"undefined":_typeof(t);return null===t||"object"!==e&&"function"!==e}function getContent(t,e){var n="";return t.forEach(function(t){if("string"==typeof t)n+=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+=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},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof 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 o=mapMark(e.mark,t.marks);n+=o?"<"+o+">":"",i=o?"</"+o+">":""}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)},unhandledBlock:function(t){var e="";return Object.keys(t.attributes).forEach(function(n){var r=isPrimitive(t.attributes[n]),i=r?t.attributes[n]:JSON.stringify(t.attributes[n]).replace(/[\\"']/g,"\\$&").replace(/\u0000/g,"\\0");e+='<div data-unhandled-attribute-name="'+n+'" data-unhandled-attribute-value="'+i+'" />'}),e}};return r}; | ||
"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 l=n[t.type]||n.textBlock;t.children=l(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="",l="";if(e.mark){var i=mapMark(e.mark,t.marks);n+=i?"<"+i+">":"",l=i?"</"+i+">":""}return e.children=getContent(e.content,r),t.span?""+n+t.span(e)+l:(e.attributes&&e.attributes.link&&(n+='<a href="'+e.attributes.link.href+'">',l="</a>"+l),""+n+getContent(e.content,r)+l)}};return r}; | ||
},{}],4:[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 l=Array.from(n);n=[],t.push(r.parseListBlocks(l))}}else t.push(r.parseSingleBlock(e))}),t}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; | ||
"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){ | ||
@@ -15,6 +15,6 @@ "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; | ||
"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; | ||
},{}],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) | ||
}); |
@@ -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 s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(e){var n=t[u][1][e];return o(n||e)},c,c.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")}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},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}}(),a=e("@sanity/block-content-to-tree"),l=r(a),s=e("./type-handlers"),c=r(s),f=new l.default,p=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,c.default)(t.blockTypeHandlers||{}),n)}return u(e,[{key:"parse",value:function(e){var t=this,n=f.parse(e);return Array.isArray(n)?n.map(function(e){return t.parseSingle(e)}).join("\n"):this.parseSingle(n)}},{key:"parseSingle",value:function(e){return this.typeHandlers[e.type]?this.typeHandlers[e.type](e):this.typeHandlers.unhandledBlock(e)}}]),e}();n.default=p},{"./type-handlers":3,"@sanity/block-content-to-tree":6}],2:[function(e,t,n){"use strict";t.exports=e("./Adapter.js")},{"./Adapter.js":1}],3:[function(e,t,n){"use strict";function r(e){var t=void 0===e?"undefined":l(e);return null===e||"object"!==t&&"function"!==t}function o(e,t){var n="";return e.forEach(function(e){if("string"==typeof e)n+=e;else{var r=t[e.type]||t.text;n+=r(e)}}),n}function i(e,t,n){var r="";return e.forEach(function(e){if("string"==typeof e)r+=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 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},l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};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||{}),l={block:function(e){return t[e.style]?(e.children=o(e.content,l),t[e.style](e)):"<"+e.style+">"+o(e.content,l)+"</"+e.style+">"},list:function(e){return n[e.itemStyle]?(e.children=i(e.items,n,l),n[e.itemStyle](e)):"<ul>"+i(e.items,n,l)+"</ul>"},span:function(t){var n="",r="";if(t.mark){var i=u(t.mark,e.marks);n+=i?"<"+i+">":"",r=i?"</"+i+">":""}return t.children=o(t.content,l),e.span?""+n+e.span(t)+r:(t.attributes&&t.attributes.link&&(n+='<a href="'+t.attributes.link.href+'">',r="</a>"+r),""+n+o(t.content,l)+r)},unhandledBlock:function(e){var t="";return Object.keys(e.attributes).forEach(function(n){var o=r(e.attributes[n]),i=o?e.attributes[n]:JSON.stringify(e.attributes[n]).replace(/[\\"']/g,"\\$&").replace(/\u0000/g,"\\0");t+='<div data-unhandled-attribute-name="'+n+'" data-unhandled-attribute-value="'+i+'" />'}),t}};return l}},{}],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"),s=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}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=s},{"./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){arguments[4][2][0].apply(n,arguments)},{"./Adapter.js":4,dup:2}],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(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")}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},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}}(),a=e("@sanity/block-content-to-tree"),l=r(a),c=e("./type-handlers"),s=r(c),f=new l.default,p=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,s.default)(t.blockTypeHandlers||{}),n)}return u(e,[{key:"parse",value:function(e){var t=this,n=f.parse(e);return Array.isArray(n)?n.map(function(e){return t.parseSingle(e)}).join("\n"):this.parseSingle(n)}},{key:"parseSingle",value:function(e){if(this.typeHandlers[e.type])return this.typeHandlers[e.type](e);throw new Error("Don't know how to handle type '"+e.type+"'")}}]),e}();n.default=p},{"./type-handlers":3,"@sanity/block-content-to-tree":6}],2:[function(e,t,n){"use strict";t.exports=e("./Adapter.js")},{"./Adapter.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.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){arguments[4][2][0].apply(n,arguments)},{"./Adapter.js":4,dup:2}],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)}); |
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
32
986
59042
+ Added@sanity/block-content-to-tree@0.0.5(transitive)
- Removed@sanity/block-content-to-tree@0.0.4(transitive)