UNPKG

ts-markdown-builder

Version:
1 lines 2.98 kB
{"version":3,"file":"block.mjs","names":["joinBlocks","maxBackticks","prefixLines","horizontalRule","heading","text","options","level","repeat","blockquote","content","codeBlock","backticks","Math","max","list","items","map","item","join","orderedList","index"],"sources":["../../src/block.ts"],"sourcesContent":["import { joinBlocks, maxBackticks, prefixLines } from './utils';\n\n/**\n * Create a horizontal rule block.\n *\n * Markdown: `---`\n */\nexport const horizontalRule = '---';\n\ntype HeadingOptions = {\n level: number;\n};\n\n/**\n * Create a heading block.\n * Markdown: `# Heading`\n *\n * @param text - The text of the heading.\n * @param level - The level of the heading (defaults to 1).\n */\nexport function heading(text: string, options?: HeadingOptions): string {\n const level = options?.level ?? 1;\n return `${'#'.repeat(level)} ${text}`;\n}\n\n/**\n * Create a blockquote block.\n *\n * Markdown:\n * ```\n * > Content\n * > Content\n * ```\n *\n * @param text - The content of the blockquote.\n */\nexport function blockquote(content: string | readonly string[]): string {\n return prefixLines(joinBlocks(content), '> ');\n}\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```\n * Content\n * ```\n *\n * @param content - The content of the code block.\n */\nexport function codeBlock(content: string): string {\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + '\\n' + content + '\\n' + '`'.repeat(backticks);\n}\n\n/**\n * Create an unordered list block.\n *\n * Markdown:\n * ```\n * - Item\n * - Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function list(items: readonly string[]): string {\n return items.map((item) => `- ${item}`).join('\\n');\n}\n\n/**\n * Create an ordered list block.\n *\n * Markdown:\n * ```\n * 1. Item\n * 2. Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function orderedList(items: readonly string[]): string {\n return items.map((item, index) => `${index + 1}. ${item}`).join('\\n');\n}\n"],"mappings":"SAASA,UAAU,EAAEC,YAAY,EAAEC,WAAW;AAO9C,OAAO,MAAMC,cAAc,GAAG,KAAK;AAanC,OAAO,SAASC,OAAOA,CAACC,IAAY,EAAEC,OAAwB,EAAU;EACtE,MAAMC,KAAK,GAAGD,OAAO,EAAEC,KAAK,IAAI,CAAC;EACjC,OAAO,GAAG,GAAG,CAACC,MAAM,CAACD,KAAK,CAAC,IAAIF,IAAI,EAAE;AACvC;AAaA,OAAO,SAASI,UAAUA,CAACC,OAAmC,EAAU;EACtE,OAAOR,WAAW,CAACF,UAAU,CAACU,OAAO,CAAC,EAAE,IAAI,CAAC;AAC/C;AAYA,OAAO,SAASC,SAASA,CAACD,OAAe,EAAU;EACjD,MAAME,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACb,YAAY,CAACS,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACI,SAAS,CAAC,GAAG,IAAI,GAAGF,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACI,SAAS,CAAC;AAC9E;AAaA,OAAO,SAASG,IAAIA,CAACC,KAAwB,EAAU;EACrD,OAAOA,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,KAAKA,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACpD;AAaA,OAAO,SAASC,WAAWA,CAACJ,KAAwB,EAAU;EAC5D,OAAOA,KAAK,CAACC,GAAG,CAAC,CAACC,IAAI,EAAEG,KAAK,KAAK,GAAGA,KAAK,GAAG,CAAC,KAAKH,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACvE","ignoreList":[]}