Commit 2cf94589 authored by Fred Chasen's avatar Fred Chasen

Add hasTextContent method for checking for breaks in layout

parent 424154a2
......@@ -28,6 +28,10 @@
break-before: right;
}
h1 {
break-before: right;
}
h2 {
break-before: right;
}
......
......@@ -18,6 +18,7 @@ import {
child,
isVisible,
isContainer,
hasTextContent,
validNode,
prevValidNode,
nextValidNode,
......@@ -110,7 +111,7 @@ class Layout {
// Check if layout has content yet
if (!hasContent) {
hasContent = isVisible(node);
hasContent = hasTextContent(node);
}
// Skip to the next node if a deep clone was rendered
......
......@@ -480,9 +480,25 @@ export function isVisible(node) {
if (isElement(node) && window.getComputedStyle(node).display !== "none") {
return true;
} else if (isText(node) &&
node.textContent.trim().length &&
hasTextContent(node) &&
window.getComputedStyle(node.parentNode).display !== "none") {
return true;
}
return false;
}
export function hasTextContent(node) {
if (isElement(node)) {
let child;
for (var i = 0; i < node.childNodes.length; i++) {
child = node.childNodes[i];
if (child && isText(child) && child.textContent.trim().length) {
return true;
}
}
} else if (isText(node) &&
node.textContent.trim().length) {
return true;
}
return false;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment