@openstax/highlighter
Advanced tools
Comparing version 1.12.0 to 1.12.1
@@ -29,2 +29,4 @@ "use strict"; | ||
const ALLOWED_ELEMENTS = BLOCK_ELEMENTS.concat(TEXT_ELEMENTS).join(','); | ||
const isEmptyTextNode = (node) => node.nodeType === NODE_TYPE.TEXT_NODE && node.textContent && !node.textContent.trim().length; | ||
const isImgOrMediaSpan = (node) => node.nodeName === 'IMG' || (node.nodeName === 'SPAN' && node.dataset.type === 'media'); | ||
function injectHighlightWrappers(highlight, options = {}) { | ||
@@ -197,3 +199,7 @@ const wrapper = createWrapper(Object.assign({ id: highlight.id, timestamp: Date.now() }, options)); | ||
} | ||
endContainer = endContainer.previousSibling; | ||
// use previous sibling for end container unless end container is an img/media span preceded by an empty text node | ||
// otherwise highlights ending on an img in firefox may not display correctly due to empty text nodes around img element | ||
if (endContainer.previousSibling && !(isImgOrMediaSpan(endContainer) && isEmptyTextNode(endContainer.previousSibling))) { | ||
endContainer = endContainer.previousSibling; | ||
} | ||
} | ||
@@ -221,4 +227,6 @@ else if (endContainer.nodeType === NODE_TYPE.TEXT_NODE) { | ||
startContainer = startContainer.childNodes.item(range.startOffset); | ||
// use next sibling for start container unless start container is an img/media span followed by an empty text node | ||
// otherwise highlights starting on an img in firefox may not display correctly due to empty text nodes around img element | ||
} | ||
else if (startContainer.nextSibling) { | ||
else if (startContainer.nextSibling && !(isImgOrMediaSpan(startContainer) && isEmptyTextNode(startContainer.nextSibling))) { | ||
startContainer = startContainer.nextSibling; | ||
@@ -225,0 +233,0 @@ } |
{ | ||
"name": "@openstax/highlighter", | ||
"version": "1.12.0", | ||
"version": "1.12.1", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
228264
57
2580