@sanity/block-tools
Advanced tools
Comparing version 0.123.0-beta.ce219b27 to 0.123.0
@@ -7,2 +7,4 @@ '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; }; | ||
var _helpers = require('./helpers'); | ||
@@ -169,6 +171,7 @@ | ||
}; | ||
for (var i = 0; i < _this.rules.length; i++) { | ||
var _loop = function _loop(i) { | ||
var rule = _this.rules[i]; | ||
if (!rule.deserialize) { | ||
continue; | ||
return 'continue'; | ||
} | ||
@@ -183,5 +186,7 @@ var ret = rule.deserialize(element, next); | ||
if (ret === undefined) { | ||
continue; | ||
return 'continue'; | ||
} else if (ret === null) { | ||
return null; | ||
return { | ||
v: null | ||
}; | ||
} else if (ret._type === '__decorator') { | ||
@@ -206,4 +211,31 @@ node = _this.deserializeDecorator(ret); | ||
} | ||
break; | ||
// Set newlines on spans orginating from a block element within a blockquote | ||
if (ret && ret._type === 'block' && ret.style === 'blockquote') { | ||
ret.children.forEach(function (child, index) { | ||
if (child._type === 'span' && child.text === '\r') { | ||
child.text = '\n\n'; | ||
if (index === 0 || index === ret.children.length - 1) { | ||
ret.children.splice(index, 1); | ||
} | ||
} | ||
}); | ||
} | ||
return 'break'; | ||
}; | ||
_loop2: for (var i = 0; i < _this.rules.length; i++) { | ||
var _ret = _loop(i); | ||
switch (_ret) { | ||
case 'continue': | ||
continue; | ||
case 'break': | ||
break _loop2; | ||
default: | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} | ||
} | ||
return node || next(element.childNodes); | ||
@@ -210,0 +242,0 @@ }; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
// Remove this cruft from the document | ||
var unwantedWordDocumentPaths = ['/html/text()', '/html/head/text()', '/html/body/text()', '//p[not(.//text())]', '//span[not(.//text())]', '//comment()', '//style', '//xml', '//script', '//meta', '//link']; | ||
var unwantedWordDocumentPaths = ['/html/text()', '/html/head/text()', '/html/body/text()', '//comment()', '//style', '//xml', '//script', '//meta', '//link']; | ||
@@ -15,0 +15,0 @@ var unwantedNodes = doc.evaluate(unwantedWordDocumentPaths.join('|'), doc, null, _index._XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); |
@@ -56,2 +56,36 @@ 'use strict'; | ||
// Blockquote element | ||
{ | ||
deserialize: function deserialize(el, next) { | ||
if ((0, _helpers.tagName)(el) !== 'blockquote') { | ||
return undefined; | ||
} | ||
var blocks = _extends({}, _constants.HTML_BLOCK_TAGS, _constants.HTML_HEADER_TAGS); | ||
delete blocks.blockquote; | ||
var children = []; | ||
el.childNodes.forEach(function (node, index) { | ||
if (node.nodeType === 1 && Object.keys(blocks).includes(node.localName.toLowerCase())) { | ||
var span = el.ownerDocument.createElement('span'); | ||
span.appendChild(el.ownerDocument.createTextNode('\r')); | ||
node.childNodes.forEach(function (cn) { | ||
span.appendChild(cn.cloneNode(true)); | ||
}); | ||
if (index !== el.childNodes.length) { | ||
span.appendChild(el.ownerDocument.createTextNode('\r')); | ||
} | ||
children.push(span); | ||
} else { | ||
children.push(node); | ||
} | ||
}); | ||
return { | ||
_type: 'block', | ||
style: 'blockquote', | ||
markDefs: [], | ||
children: next(children) | ||
}; | ||
} | ||
}, | ||
// Block elements | ||
@@ -58,0 +92,0 @@ { |
{ | ||
"name": "@sanity/block-tools", | ||
"version": "0.123.0-beta.ce219b27", | ||
"version": "0.123.0", | ||
"description": "Can format HTML, Slate JSON or Sanity block array into any other format.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
53627
1290
23