@wordpress/blocks
Version:
Block API for WordPress.
57 lines (55 loc) • 2.07 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/blocks/src/api/raw-handling/is-inline-content.js
var is_inline_content_exports = {};
__export(is_inline_content_exports, {
default: () => isInlineContent
});
module.exports = __toCommonJS(is_inline_content_exports);
var import_dom = require("@wordpress/dom");
function isInline(node, contextTag) {
if ((0, import_dom.isTextContent)(node)) {
return true;
}
if (!contextTag) {
return false;
}
const tag = node.nodeName.toLowerCase();
const inlineAllowedTagGroups = [
["ul", "li", "ol"],
["h1", "h2", "h3", "h4", "h5", "h6"]
];
return inlineAllowedTagGroups.some(
(tagGroup) => [tag, contextTag].filter((t) => !tagGroup.includes(t)).length === 0
);
}
function deepCheck(nodes, contextTag) {
return nodes.every(
(node) => isInline(node, contextTag) && deepCheck(Array.from(node.children), contextTag)
);
}
function isDoubleBR(node) {
return node.nodeName === "BR" && node.previousSibling && node.previousSibling.nodeName === "BR";
}
function isInlineContent(HTML, contextTag) {
const doc = document.implementation.createHTMLDocument("");
doc.body.innerHTML = HTML;
const nodes = Array.from(doc.body.children);
return !nodes.some(isDoubleBR) && deepCheck(nodes, contextTag);
}
//# sourceMappingURL=is-inline-content.js.map