UNPKG

@hedgedoc/html-to-react

Version:

Parse HTML into React components

31 lines 1.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapHtmlAttributesToReactElementAttributes = void 0; const booleanAttributes_js_1 = __importDefault(require("../dom/attributes/booleanAttributes.js")); const reactAttributes_js_1 = __importDefault(require("../dom/attributes/reactAttributes.js")); const isValidTagOrAttributeName_js_1 = require("./isValidTagOrAttributeName.js"); function getParsedAttributeValue(attribute, value) { if (booleanAttributes_js_1.default.has(attribute.toLowerCase())) { value = attribute; } return value; } function isEventHandlerAttribute(attribute) { return attribute.startsWith('on'); } function mapHtmlAttributesToReactElementAttributes(attributes) { return Object.keys(attributes) .filter((attribute) => !isEventHandlerAttribute(attribute) && (0, isValidTagOrAttributeName_js_1.isValidTagOrAttributeName)(attribute)) .reduce((mappedAttributes, attribute) => { const lowerCaseAttribute = attribute.toLowerCase(); const name = reactAttributes_js_1.default[lowerCaseAttribute] || attribute; mappedAttributes[name] = getParsedAttributeValue(name, attributes[attribute]); return mappedAttributes; }, {}); } exports.mapHtmlAttributesToReactElementAttributes = mapHtmlAttributesToReactElementAttributes; //# sourceMappingURL=mapHtmlAttributesToReactElementAttributes.js.map