@wordpress/blocks
Version:
Block API for WordPress.
45 lines (44 loc) • 1.18 kB
JavaScript
// packages/blocks/src/api/matchers.js
import { attr, prop, text, query } from "hpq";
import { RichTextData } from "@wordpress/rich-text";
import { matcher } from "./node";
import { matcher as matcher2 } from "./children";
function html(selector, multilineTag) {
return (domNode) => {
let match = domNode;
if (selector) {
match = domNode.querySelector(selector);
}
if (!match) {
return "";
}
if (multilineTag) {
let value = "";
const length = match.children.length;
for (let index = 0; index < length; index++) {
const child = match.children[index];
if (child.nodeName.toLowerCase() !== multilineTag) {
continue;
}
value += child.outerHTML;
}
return value;
}
return match.innerHTML;
};
}
var richText = (selector, preserveWhiteSpace) => (el) => {
const target = selector ? el.querySelector(selector) : el;
return target ? RichTextData.fromHTMLElement(target, { preserveWhiteSpace }) : RichTextData.empty();
};
export {
attr,
matcher2 as children,
html,
matcher as node,
prop,
query,
richText,
text
};
//# sourceMappingURL=matchers.js.map