@wordpress/blocks
Version:
Block API for WordPress.
33 lines (32 loc) • 980 B
JavaScript
// packages/blocks/src/api/parser/fix-aria-label.js
import { hasBlockSupport } from "../registration";
import { parseWithAttributeSchema } from "./get-block-attributes";
var ARIA_LABEL_ATTR_SCHEMA = {
type: "string",
source: "attribute",
selector: "[data-aria-label] > *",
attribute: "aria-label"
};
function getHTMLRootElementAriaLabel(innerHTML) {
const parsed = parseWithAttributeSchema(
`<div data-aria-label>${innerHTML}</div>`,
ARIA_LABEL_ATTR_SCHEMA
);
return parsed;
}
function fixAriaLabel(blockAttributes, blockType, innerHTML) {
if (!hasBlockSupport(blockType, "ariaLabel", false)) {
return blockAttributes;
}
const modifiedBlockAttributes = { ...blockAttributes };
const ariaLabel = getHTMLRootElementAriaLabel(innerHTML);
if (ariaLabel) {
modifiedBlockAttributes.ariaLabel = ariaLabel;
}
return modifiedBlockAttributes;
}
export {
fixAriaLabel,
getHTMLRootElementAriaLabel
};
//# sourceMappingURL=fix-aria-label.js.map