UNPKG

ts-markdown-builder

Version:
1 lines 2.02 kB
{"version":3,"file":"html.mjs","names":["lineBreak","disclosure","title","content","options","headerHack","startsWith","open","escapeMarkdownInHtml","markdown"],"sources":["../../src/html.ts"],"sourcesContent":["/**\n * Create a line break.\n *\n * Markdown (as HTML): `<br/>`\n */\nexport const lineBreak = '<br/>';\n\n/**\n * Options for the `disclosure` block.\n */\nexport type DisclosureOptions = {\n /**\n * Whether the disclosure block should be open by default (defaults to false).\n */\n open?: boolean;\n};\n\n/**\n * Create a disclosure block.\n *\n * Markdown (as HTML):\n * ```\n * <details>\n * <summary>Title</summary>\n * Content\n * </details>\n * ```\n *\n * @param title - The title of the disclosure (text only or markdown heading: `# heading`).\n * @param content - The content of the disclosure (can include markdown).\n * @param options - The options for the disclosure.\n */\nexport function disclosure(title: string, content: string, options?: DisclosureOptions): string {\n // Add extra with lines to render header properly. New line should not be added for regular text\n // as it messes up the formatting.\n const headerHack = title.startsWith('#') ? '\\n\\n' : '';\n\n return `<details${options?.open ? ' open' : ''}>\n<summary>${headerHack}${title}${headerHack}</summary>\n${escapeMarkdownInHtml(content)}\n</details>`;\n}\n\n// Blank lines are required for rendering a markdown section inside html tag.\n// See https://gist.github.com/scmx/eca72d44afee0113ceb0349dd54a84a2\nfunction escapeMarkdownInHtml(markdown: string): string {\n return `\\n${markdown}\\n`;\n}\n"],"mappings":"AAKA,OAAO,MAAMA,SAAS,GAAG,OAAO;AA2BhC,OAAO,SAASC,UAAUA,CAACC,KAAa,EAAEC,OAAe,EAAEC,OAA2B,EAAU;EAG9F,MAAMC,UAAU,GAAGH,KAAK,CAACI,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,EAAE;EAEtD,OAAO,WAAWF,OAAO,EAAEG,IAAI,GAAG,OAAO,GAAG,EAAE;AAChD,WAAWF,UAAU,GAAGH,KAAK,GAAGG,UAAU;AAC1C,EAAEG,oBAAoB,CAACL,OAAO,CAAC;AAC/B,WAAW;AACX;AAIA,SAASK,oBAAoBA,CAACC,QAAgB,EAAU;EACtD,OAAO,KAAKA,QAAQ,IAAI;AAC1B","ignoreList":[]}