@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
63 lines (61 loc) • 2.72 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_interpreter_getContent_getContent = require('../../interpreter/getContent/getContent.cjs');
const require_transpiler_html_getHTMLCustomComponents = require('../html/getHTMLCustomComponents.cjs');
const require_transpiler_markdown_getMarkdownMetadata = require('./getMarkdownMetadata.cjs');
const require_transpiler_markdown_validateMarkdown = require('./validateMarkdown.cjs');
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
//#region src/transpiler/markdown/markdown.ts
const awaitContent = async (content) => {
if (typeof content === "string" || typeof content === "object") return content;
if (typeof content === "function") return content();
if (typeof content.then === "function") return await content;
};
/**
* Function intended to be used to build intlayer dictionaries.
*
* Allow to pick a content based on a quantity.
*
* Usage:
*
* ```ts
* markdown('## Hello world!');
* ```
*
*/
const markdown = (content, components) => {
const metadata = async () => {
const flatContent = require_interpreter_getContent_getContent.getContent(await awaitContent(content), {
dictionaryKey: "",
keyPath: []
});
if (typeof flatContent === "string") {
if (process.env.NODE_ENV !== "production") {
const { issues } = require_transpiler_markdown_validateMarkdown.validateMarkdown(flatContent);
for (const issue of issues) if (issue.type === "error") console.error(`[intlayer/markdown] ${issue.message}`);
else console.warn(`[intlayer/markdown] ${issue.message}`);
}
return require_transpiler_markdown_getMarkdownMetadata.getMarkdownMetadata(flatContent);
}
};
const getComponents = () => {
if (components) return components;
if (typeof content === "string") 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.MARKDOWN, content, {
metadata,
tags: getComponents()
});
};
//#endregion
exports.md = markdown;
//# sourceMappingURL=markdown.cjs.map