UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

36 lines (34 loc) 1.07 kB
import { getContent } from "../../interpreter/getContent/getContent.mjs"; import { getMarkdownMetadata } from "./getMarkdownMetadata.mjs"; import { NodeType, formatNodeType } from "@intlayer/types"; //#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) => { const metadata = async () => { const flatContent = getContent(await awaitContent(content), { dictionaryKey: "", keyPath: [] }); if (typeof flatContent === "string") return getMarkdownMetadata(flatContent); }; return formatNodeType(NodeType.Markdown, content, { metadata }); }; //#endregion export { markdown as md }; //# sourceMappingURL=markdown.mjs.map