@sanity/block-tools
Advanced tools
Comparing version 0.124.0-alpha.35b4b49a to 0.124.0-alpha.d5ac0a90
@@ -26,8 +26,2 @@ 'use strict'; | ||
/** | ||
* A internal variable to keep track of annotation mark definitions within the 'run' of a block | ||
* | ||
*/ | ||
var _markDefsWithinBlock = []; | ||
/** | ||
* HTML Deserializer | ||
@@ -69,3 +63,5 @@ * | ||
}; | ||
this.blocks = []; | ||
this._blocks = []; | ||
this._currentBlockChildren = []; | ||
this._currentBlockMarkDefs = []; | ||
} | ||
@@ -140,3 +136,5 @@ | ||
if (node._type === 'block') { | ||
_this.blocks.push(node); | ||
_this._blocks.push(node); | ||
} else { | ||
_this._currentBlockChildren.push(node); | ||
} | ||
@@ -183,3 +181,8 @@ break; | ||
} | ||
var ret = rule.deserialize(element, next, _this.blocks, _this.deserializeElements); | ||
var ret = rule.deserialize(element, next, { | ||
blocks: _this._blocks, | ||
currentBlockChildren: _this._currentBlockChildren, | ||
currentBlockMarkDefs: _this._currentBlockMarkDefs, | ||
deserialize: _this.deserializeElements | ||
}); | ||
var type = (0, _resolveJsType2.default)(ret); | ||
@@ -201,5 +204,6 @@ | ||
node = _this.deserializeAnnotation(ret); | ||
} else if (ret._type === 'block' && _markDefsWithinBlock.length) { | ||
ret.markDefs = _markDefsWithinBlock; | ||
_markDefsWithinBlock = []; // Reset here | ||
} else if (ret._type === 'block' && _this._currentBlockMarkDefs.length) { | ||
ret.markDefs = _this._currentBlockMarkDefs; | ||
_this._currentBlockMarkDefs = []; // Reset here | ||
_this._currentBlockChildren = []; | ||
node = ret; | ||
@@ -279,3 +283,3 @@ } else { | ||
_markDefsWithinBlock.push(markDef); | ||
_this._currentBlockMarkDefs.push(markDef); | ||
var applyAnnotation = function applyAnnotation(node) { | ||
@@ -282,0 +286,0 @@ if (node._type === '__annotation') { |
@@ -20,5 +20,3 @@ "use strict"; | ||
// xPaths for elements that will be removed from the document | ||
var unwantedPaths = ["//*[name() = 'o:p']" | ||
// "//span[@style='mso-list:Ignore']", | ||
]; | ||
var unwantedPaths = ["//*[name() = 'o:p']"]; | ||
@@ -25,0 +23,0 @@ // xPaths for elements that needs to be remapped into other tags |
@@ -23,6 +23,2 @@ 'use strict'; | ||
function notesEnabled(options) { | ||
return options.enabledBlockAnnotations.includes('blockNote'); | ||
} | ||
function isNormalEmptyParagraph(el) { | ||
@@ -96,2 +92,23 @@ return (0, _helpers.tagName)(el) === 'p' && el.textContent === '' && el.textContent === '' && el.className === 'MsoNormal'; | ||
var blockNotesEnabled = options.enabledBlockAnnotations.includes('blockNote'); | ||
var blockNoteAnnotationMarker = void 0; | ||
if (blockContentType && blockNotesEnabled) { | ||
var blockType = blockContentType.of.find(function (ofType) { | ||
return ofType.name === 'block'; | ||
}); | ||
var spansType = blockType.fields.find(function (field) { | ||
return field.name === 'spans'; | ||
}).type; | ||
var annotations = spansType.of.find(function (ofType) { | ||
return ofType.name === 'span'; | ||
}).annotations; | ||
var blockNoteType = annotations.find(function (type) { | ||
return type.name === 'blockNote'; | ||
}); | ||
if (blockNoteType) { | ||
blockNoteAnnotationMarker = blockNoteType.annotationMarker; | ||
} | ||
} | ||
return [ | ||
@@ -137,3 +154,3 @@ // Fix weird paragraphing within Word (paragraph is more of a line break) | ||
if ((0, _helpers.tagName)(el) === 'a' && (footnoteId = getFootnoteLinkElementId(el))) { | ||
if (!notesEnabled(options)) { | ||
if (!blockNotesEnabled) { | ||
return undefined; | ||
@@ -147,6 +164,7 @@ } | ||
}; | ||
var children = blockNoteAnnotationMarker ? [el.ownerDocument.createTextNode(blockNoteAnnotationMarker)] : el.childNodes; | ||
return { | ||
_type: '__annotation', | ||
markDef: markDef, | ||
children: next(el.childNodes) | ||
children: next(children) | ||
}; | ||
@@ -159,6 +177,9 @@ } | ||
{ | ||
deserialize: function deserialize(el, next, blocks, _deserialize) { | ||
deserialize: function deserialize(el, next, _ref) { | ||
var blocks = _ref.blocks, | ||
_deserialize = _ref.deserialize; | ||
var footnoteId = void 0; | ||
if ((0, _helpers.tagName)(el) === 'div' && (footnoteId = getFootnoteContentElementId(el))) { | ||
if (!notesEnabled(options)) { | ||
if (!blockNotesEnabled) { | ||
return undefined; | ||
@@ -189,3 +210,3 @@ } | ||
if ((0, _helpers.tagName)(el) === 'a' && (endnoteId = getEndnoteLinkElementId(el))) { | ||
if (!notesEnabled(options)) { | ||
if (!blockNotesEnabled) { | ||
return undefined; | ||
@@ -199,6 +220,7 @@ } | ||
}; | ||
var children = blockNoteAnnotationMarker ? [el.ownerDocument.createTextNode(blockNoteAnnotationMarker)] : el.childNodes; | ||
return { | ||
_type: '__annotation', | ||
markDef: markDef, | ||
children: next(el.childNodes) | ||
children: next(children) | ||
}; | ||
@@ -211,6 +233,9 @@ } | ||
{ | ||
deserialize: function deserialize(el, next, blocks, _deserialize2) { | ||
deserialize: function deserialize(el, next, _ref2) { | ||
var blocks = _ref2.blocks, | ||
_deserialize2 = _ref2.deserialize; | ||
var endnoteId = void 0; | ||
if ((0, _helpers.tagName)(el) === 'div' && (endnoteId = getEndnoteContentElementId(el))) { | ||
if (!notesEnabled(options)) { | ||
if (!blockNotesEnabled) { | ||
return undefined; | ||
@@ -217,0 +242,0 @@ } |
{ | ||
"name": "@sanity/block-tools", | ||
"version": "0.124.0-alpha.35b4b49a", | ||
"version": "0.124.0-alpha.d5ac0a90", | ||
"description": "Can format HTML, Slate JSON or Sanity block array into any other format.", | ||
@@ -39,3 +39,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@sanity/schema": "0.124.0-alpha.35b4b49a", | ||
"@sanity/schema": "0.124.0-alpha.d5ac0a90", | ||
"assert": "^1.4.1", | ||
@@ -68,4 +68,3 @@ "babel-cli": "^6.24.1", | ||
"jsdom": "11.3.0", | ||
"wgxpath": "^1.2.0", | ||
"xpath": "^0.0.24" | ||
"wgxpath": "^1.2.0" | ||
}, | ||
@@ -72,0 +71,0 @@ "directories": { |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
227754
29
1481
0