@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
44 lines (42 loc) • 1.87 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_transpiler_html_getHTMLCustomComponents = require('./getHTMLCustomComponents.cjs');
const require_transpiler_html_validateHTML = require('./validateHTML.cjs');
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
//#region src/transpiler/html/html.ts
/**
* Function intended to be used to build intlayer dictionaries.
*
* Allow to parse HTML/JSX-like strings and replace tags with components during interpretation.
*
* Usage:
*
* ```ts
* html('Hello <b>World</b>')
* ```
*
*/
const html = (content, components) => {
const getComponents = () => {
if (components) return components;
if (typeof content === "string") {
const { issues } = require_transpiler_html_validateHTML.validateHTML(content);
for (const issue of issues) if (issue.type === "error") console.error(`[intlayer/html] ${issue.message}`);
else console.warn(`[intlayer/html] ${issue.message}`);
return require_transpiler_html_getHTMLCustomComponents.getHTMLCustomComponents(content);
}
let stringContent;
if (typeof content === "function") stringContent = content();
else if (typeof content.then === "function") stringContent = async () => require_transpiler_html_getHTMLCustomComponents.getHTMLCustomComponents(await content);
if (typeof stringContent === "string") return require_transpiler_html_getHTMLCustomComponents.getHTMLCustomComponents(stringContent);
try {
return require_transpiler_html_getHTMLCustomComponents.getHTMLCustomComponents(JSON.stringify(content));
} catch (_e) {
return [];
}
};
return (0, _intlayer_types_nodeType.formatNodeType)(_intlayer_types_nodeType.HTML, content, { tags: getComponents() });
};
//#endregion
exports.html = html;
//# sourceMappingURL=html.cjs.map