ts-markdown-builder 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/commonjs/block.js +4 -0
- package/dist/commonjs/block.js.map +1 -1
- package/dist/commonjs/index.js +6 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/inline.js +4 -4
- package/dist/commonjs/inline.js.map +1 -1
- package/dist/commonjs/utils.js +2 -2
- package/dist/commonjs/utils.js.map +1 -1
- package/dist/esm/block.mjs +3 -0
- package/dist/esm/block.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/inline.mjs +4 -4
- package/dist/esm/inline.mjs.map +1 -1
- package/dist/esm/utils.mjs +2 -2
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/types/block.d.ts +14 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/inline.d.ts +3 -5
- package/package.json +27 -78
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# TS Markdown Builder
|
|
8
8
|
|
|
9
|
-
Elegant
|
|
9
|
+
Elegant Markdown builder for TypeScript: zero dependencies, tree-shakable, under 1 kB.
|
|
10
10
|
|
|
11
11
|
## Goal
|
|
12
12
|
|
|
@@ -64,25 +64,26 @@ It supports:
|
|
|
64
64
|
### Block
|
|
65
65
|
- [`heading(text: string, options?: { level: number = 1 })`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#heading)
|
|
66
66
|
- [`blockquote(text: string | string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#blockquote)
|
|
67
|
+
- [`alert(type: AlertType, content: string | string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#alert) - alert (callout); type is `'note' | 'tip' | 'important' | 'warning' | 'caution'` _(GitHub extension)_
|
|
67
68
|
- [`codeBlock(text: string, options?: { language?: string = '' })`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#codeblock)
|
|
68
69
|
- [`list(items: string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#list)
|
|
69
70
|
- [`orderedList(items: string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#orderedlist)
|
|
70
|
-
- [`taskList(items: (string | TaskListItem)[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#tasklist) -
|
|
71
|
+
- [`taskList(items: (string | TaskListItem)[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#tasklist) - task list with checkboxes (items can be strings or `{ text: string, done?: boolean }`) _(GFM extension)_
|
|
71
72
|
- [`horizontalRule`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#horizontalrule)
|
|
72
73
|
|
|
73
74
|
### Inline
|
|
74
75
|
|
|
75
76
|
- [`bold(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#bold)
|
|
76
77
|
- [`italic(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#italic)
|
|
77
|
-
- [`strikethrough(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#strikethrough)
|
|
78
|
+
- [`strikethrough(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#strikethrough) _(GFM extension)_
|
|
78
79
|
- [`code(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#code)
|
|
79
|
-
- [`link(url: string, text?: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#link) - link
|
|
80
|
+
- [`link(url: string, text?: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#link) - link
|
|
80
81
|
- [`image(url: string, text?: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#image)
|
|
81
82
|
- [`escape(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#escape)
|
|
82
83
|
|
|
83
84
|
### Table
|
|
84
85
|
|
|
85
|
-
- [`table(headers: string[], rows: string[][])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#table)
|
|
86
|
+
- [`table(headers: string[], rows: string[][])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#table) _(GFM extension)_
|
|
86
87
|
|
|
87
88
|
### HTML
|
|
88
89
|
|
package/dist/commonjs/block.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
exports.alert = alert;
|
|
3
4
|
exports.blockquote = blockquote;
|
|
4
5
|
exports.codeBlock = codeBlock;
|
|
5
6
|
exports.heading = heading;
|
|
@@ -16,6 +17,9 @@ function heading(text, options) {
|
|
|
16
17
|
function blockquote(content) {
|
|
17
18
|
return (0, _utils.prefixLines)((0, _utils.joinBlocks)(content), '> ');
|
|
18
19
|
}
|
|
20
|
+
function alert(type, content) {
|
|
21
|
+
return blockquote(`[!${type.toUpperCase()}]\n${(0, _utils.joinBlocks)(content)}`);
|
|
22
|
+
}
|
|
19
23
|
function codeBlock(content, options) {
|
|
20
24
|
const language = options?.language ?? '';
|
|
21
25
|
const backticks = Math.max((0, _utils.maxBackticks)(content), 2) + 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","names":["horizontalRule","exports","heading","text","options","level","repeat","blockquote","content","prefixLines","joinBlocks","codeBlock","language","backticks","Math","max","maxBackticks","list","items","map","item","join","orderedList","index","taskList","result","done","push"],"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\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\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\nexport type TaskListItem = {\n text: string;\n done?: boolean;\n};\n\n/**\n * Create a task list block.\n *\n * Markdown:\n * ```\n * - [x] Done item\n * - [ ] Pending item\n * ```\n *\n * @param items - The items of the task list.\n */\nexport function taskList(items: readonly (string | TaskListItem)[]): string {\n const result = [];\n for (const item of items) {\n const text = typeof item === 'string' ? item : item.text;\n const done = typeof item === 'string' ? false : item.done;\n result.push(`- [${done ? 'x' : ' '}] ${text}`);\n }\n\n return result.join('\\n');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"block.js","names":["horizontalRule","exports","heading","text","options","level","repeat","blockquote","content","prefixLines","joinBlocks","alert","type","toUpperCase","codeBlock","language","backticks","Math","max","maxBackticks","list","items","map","item","join","orderedList","index","taskList","result","done","push"],"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\nexport type AlertType = 'note' | 'tip' | 'important' | 'warning' | 'caution';\n\n/**\n * Create a GitHub alert (callout) block.\n *\n * Markdown:\n * ```\n * > [!NOTE]\n * > Content\n * ```\n *\n * @param type - The alert type: `note`, `tip`, `important`, `warning` or `caution`.\n * @param content - The content of the alert.\n */\nexport function alert(type: AlertType, content: string | readonly string[]): string {\n return blockquote(`[!${type.toUpperCase()}]\\n${joinBlocks(content)}`);\n}\n\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\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\nexport type TaskListItem = {\n text: string;\n done?: boolean;\n};\n\n/**\n * Create a task list block.\n *\n * Markdown:\n * ```\n * - [x] Done item\n * - [ ] Pending item\n * ```\n *\n * @param items - The items of the task list.\n */\nexport function taskList(items: readonly (string | TaskListItem)[]): string {\n const result = [];\n for (const item of items) {\n const text = typeof item === 'string' ? item : item.text;\n const done = typeof item === 'string' ? false : item.done;\n result.push(`- [${done ? 'x' : ' '}] ${text}`);\n }\n\n return result.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;AAOO,MAAMA,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,KAAK;AAa5B,SAASE,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;AAaO,SAASI,UAAUA,CAACC,OAAmC,EAAU;EACtE,OAAO,IAAAC,kBAAW,EAAC,IAAAC,iBAAU,EAACF,OAAO,CAAC,EAAE,IAAI,CAAC;AAC/C;AAgBO,SAASG,KAAKA,CAACC,IAAe,EAAEJ,OAAmC,EAAU;EAClF,OAAOD,UAAU,CAAC,KAAKK,IAAI,CAACC,WAAW,CAAC,CAAC,MAAM,IAAAH,iBAAU,EAACF,OAAO,CAAC,EAAE,CAAC;AACvE;AAiBO,SAASM,SAASA,CAACN,OAAe,EAAEJ,OAA0B,EAAU;EAC7E,MAAMW,QAAQ,GAAGX,OAAO,EAAEW,QAAQ,IAAI,EAAE;EACxC,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,IAAAC,mBAAY,EAACX,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACU,SAAS,CAAC,GAAGD,QAAQ,GAAG,IAAI,GAAGP,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACU,SAAS,CAAC;AACzF;AAaO,SAASI,IAAIA,CAACC,KAAwB,EAAU;EACrD,OAAOA,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,KAAKA,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACpD;AAaO,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;AAkBO,SAASG,QAAQA,CAACN,KAAyC,EAAU;EAC1E,MAAMO,MAAM,GAAG,EAAE;EACjB,KAAK,MAAML,IAAI,IAAIF,KAAK,EAAE;IACxB,MAAMlB,IAAI,GAAG,OAAOoB,IAAI,KAAK,QAAQ,GAAGA,IAAI,GAAGA,IAAI,CAACpB,IAAI;IACxD,MAAM0B,IAAI,GAAG,OAAON,IAAI,KAAK,QAAQ,GAAG,KAAK,GAAGA,IAAI,CAACM,IAAI;IACzDD,MAAM,CAACE,IAAI,CAAC,MAAMD,IAAI,GAAG,GAAG,GAAG,GAAG,KAAK1B,IAAI,EAAE,CAAC;EAChD;EAEA,OAAOyB,MAAM,CAACJ,IAAI,CAAC,IAAI,CAAC;AAC1B","ignoreList":[]}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n horizontalRule,\n heading,\n blockquote,\n orderedList,\n list,\n codeBlock,\n taskList,\n} from './block';\nexport { code, italic, bold, strikethrough, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\nexport type { TaskListItem } from './block';\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n horizontalRule,\n heading,\n blockquote,\n alert,\n orderedList,\n list,\n codeBlock,\n taskList,\n} from './block';\nexport { code, italic, bold, strikethrough, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\nexport type { AlertType, TaskListItem } from './block';\n"],"mappings":"","ignoreList":[]}
|
package/dist/commonjs/inline.js
CHANGED
|
@@ -19,12 +19,12 @@ function strikethrough(text) {
|
|
|
19
19
|
function code(text) {
|
|
20
20
|
const backticksCount = (0, _utils.maxBackticks)(text) + 1;
|
|
21
21
|
const backticks = '`'.repeat(backticksCount);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
return `${backticks}${
|
|
22
|
+
const needsPadding = text.startsWith('`') || text.endsWith('`') || text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text);
|
|
23
|
+
const padding = needsPadding ? ' ' : '';
|
|
24
|
+
return `${backticks}${padding}${text}${padding}${backticks}`;
|
|
25
25
|
}
|
|
26
26
|
function link(url, text) {
|
|
27
|
-
return
|
|
27
|
+
return `[${text || url}](${url})`;
|
|
28
28
|
}
|
|
29
29
|
function image(url, text) {
|
|
30
30
|
return ``;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline.js","names":["italic","text","bold","strikethrough","code","backticksCount","maxBackticks","backticks","repeat","
|
|
1
|
+
{"version":3,"file":"inline.js","names":["italic","text","bold","strikethrough","code","backticksCount","maxBackticks","backticks","repeat","needsPadding","startsWith","endsWith","test","padding","link","url","image"],"sources":["../../src/inline.ts"],"sourcesContent":["import { maxBackticks } from './utils';\n\n/**\n * Create an italic text.\n *\n * Markdown: `*text*`\n *\n * @param text - The text to be italicized.\n */\nexport function italic(text: string): string {\n return `*${text}*`;\n}\n\n/**\n * Create a bold text.\n *\n * Markdown: `**text**`\n *\n * @param text - The text to be bolded.\n */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/**\n * Create a strikethrough text.\n *\n * Markdown: `~~text~~`\n *\n * @param text - The text to be struck through.\n */\nexport function strikethrough(text: string): string {\n return `~~${text}~~`;\n}\n\n/**\n * Create a code text.\n *\n * Markdown: `code`\n *\n * @param text - The text to be marked as code.\n */\nexport function code(text: string): string {\n const backticksCount = maxBackticks(text) + 1;\n const backticks = '`'.repeat(backticksCount);\n const needsPadding =\n text.startsWith('`') ||\n text.endsWith('`') ||\n (text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text));\n const padding = needsPadding ? ' ' : '';\n return `${backticks}${padding}${text}${padding}${backticks}`;\n}\n\n/**\n * Create a link span.\n *\n * Markdown: `[text](url)`, or `[url](url)` when `text` is not provided.\n *\n * @param url - The URL to be linked.\n * @param text - The title for the link (optional, defaults to `url`).\n */\nexport function link(url: string, text?: string): string {\n return `[${text || url}](${url})`;\n}\n\n/**\n * Create an image text.\n *\n * Markdown: ``\n *\n * @param url - The URL of the image.\n * @param text - The description for the image (optional).\n */\nexport function image(url: string, text?: string): string {\n return ``;\n}\n"],"mappings":";;;;;;;;;AASO,SAASA,MAAMA,CAACC,IAAY,EAAU;EAC3C,OAAO,IAAIA,IAAI,GAAG;AACpB;AASO,SAASC,IAAIA,CAACD,IAAY,EAAU;EACzC,OAAO,KAAKA,IAAI,IAAI;AACtB;AASO,SAASE,aAAaA,CAACF,IAAY,EAAU;EAClD,OAAO,KAAKA,IAAI,IAAI;AACtB;AASO,SAASG,IAAIA,CAACH,IAAY,EAAU;EACzC,MAAMI,cAAc,GAAG,IAAAC,mBAAY,EAACL,IAAI,CAAC,GAAG,CAAC;EAC7C,MAAMM,SAAS,GAAG,GAAG,CAACC,MAAM,CAACH,cAAc,CAAC;EAC5C,MAAMI,YAAY,GAChBR,IAAI,CAACS,UAAU,CAAC,GAAG,CAAC,IACpBT,IAAI,CAACU,QAAQ,CAAC,GAAG,CAAC,IACjBV,IAAI,CAACS,UAAU,CAAC,GAAG,CAAC,IAAIT,IAAI,CAACU,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAACC,IAAI,CAACX,IAAI,CAAE;EACnE,MAAMY,OAAO,GAAGJ,YAAY,GAAG,GAAG,GAAG,EAAE;EACvC,OAAO,GAAGF,SAAS,GAAGM,OAAO,GAAGZ,IAAI,GAAGY,OAAO,GAAGN,SAAS,EAAE;AAC9D;AAUO,SAASO,IAAIA,CAACC,GAAW,EAAEd,IAAa,EAAU;EACvD,OAAO,IAAIA,IAAI,IAAIc,GAAG,KAAKA,GAAG,GAAG;AACnC;AAUO,SAASC,KAAKA,CAACD,GAAW,EAAEd,IAAa,EAAU;EACxD,OAAO,KAAKA,IAAI,IAAI,EAAE,KAAKc,GAAG,GAAG;AACnC","ignoreList":[]}
|
package/dist/commonjs/utils.js
CHANGED
|
@@ -21,8 +21,8 @@ function escape(text) {
|
|
|
21
21
|
function maxBackticks(text) {
|
|
22
22
|
let max = 0;
|
|
23
23
|
let current = 0;
|
|
24
|
-
for (
|
|
25
|
-
if (
|
|
24
|
+
for (const char of text) {
|
|
25
|
+
if (char === '`') {
|
|
26
26
|
current++;
|
|
27
27
|
max = Math.max(max, current);
|
|
28
28
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","
|
|
1
|
+
{"version":3,"file":"utils.js","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","char","Math"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Join blocks of text into a single markdown document (string).\n *\n * @param blocks - The blocks of text to join.\n * @returns Markdown document string.\n */\nexport function joinBlocks(blocks: string | readonly string[]): string {\n blocks = typeof blocks === 'string' ? [blocks] : blocks;\n\n return blocks.map(trimBlock).filter(Boolean).join('\\n\\n');\n}\n\nfunction trimBlock(block: string): string {\n return block.replace(/^\\n+|\\n+$/g, '');\n}\n\nexport function prefixLines(text: string, prefix: string): string {\n const lines = text.split('\\n');\n return lines.map((line) => `${prefix}${line}`).join('\\n');\n}\n\nexport function escape(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!|<>])/g, '\\\\$1');\n}\n\nexport function maxBackticks(text: string): number {\n let max = 0;\n let current = 0;\n\n for (const char of text) {\n if (char === '`') {\n current++;\n max = Math.max(max, current);\n } else {\n current = 0;\n }\n }\n\n return max;\n}\n"],"mappings":";;;;;;AAMO,SAASA,UAAUA,CAACC,MAAkC,EAAU;EACrEA,MAAM,GAAG,OAAOA,MAAM,KAAK,QAAQ,GAAG,CAACA,MAAM,CAAC,GAAGA,MAAM;EAEvD,OAAOA,MAAM,CAACC,GAAG,CAACC,SAAS,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,MAAM,CAAC;AAC3D;AAEA,SAASH,SAASA,CAACI,KAAa,EAAU;EACxC,OAAOA,KAAK,CAACC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;AACxC;AAEO,SAASC,WAAWA,CAACC,IAAY,EAAEC,MAAc,EAAU;EAChE,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC;EAC9B,OAAOD,KAAK,CAACV,GAAG,CAAEY,IAAI,IAAK,GAAGH,MAAM,GAAGG,IAAI,EAAE,CAAC,CAACR,IAAI,CAAC,IAAI,CAAC;AAC3D;AAEO,SAASS,MAAMA,CAACL,IAAY,EAAU;EAC3C,OAAOA,IAAI,CAACF,OAAO,CAAC,4BAA4B,EAAE,MAAM,CAAC;AAC3D;AAEO,SAASQ,YAAYA,CAACN,IAAY,EAAU;EACjD,IAAIO,GAAG,GAAG,CAAC;EACX,IAAIC,OAAO,GAAG,CAAC;EAEf,KAAK,MAAMC,IAAI,IAAIT,IAAI,EAAE;IACvB,IAAIS,IAAI,KAAK,GAAG,EAAE;MAChBD,OAAO,EAAE;MACTD,GAAG,GAAGG,IAAI,CAACH,GAAG,CAACA,GAAG,EAAEC,OAAO,CAAC;IAC9B,CAAC,MAAM;MACLA,OAAO,GAAG,CAAC;IACb;EACF;EAEA,OAAOD,GAAG;AACZ","ignoreList":[]}
|
package/dist/esm/block.mjs
CHANGED
|
@@ -7,6 +7,9 @@ export function heading(text, options) {
|
|
|
7
7
|
export function blockquote(content) {
|
|
8
8
|
return prefixLines(joinBlocks(content), '> ');
|
|
9
9
|
}
|
|
10
|
+
export function alert(type, content) {
|
|
11
|
+
return blockquote(`[!${type.toUpperCase()}]\n${joinBlocks(content)}`);
|
|
12
|
+
}
|
|
10
13
|
export function codeBlock(content, options) {
|
|
11
14
|
const language = options?.language ?? '';
|
|
12
15
|
const backticks = Math.max(maxBackticks(content), 2) + 1;
|
package/dist/esm/block.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.mjs","names":["joinBlocks","maxBackticks","prefixLines","horizontalRule","heading","text","options","level","repeat","blockquote","content","codeBlock","language","backticks","Math","max","list","items","map","item","join","orderedList","index","taskList","result","done","push"],"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\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\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\nexport type TaskListItem = {\n text: string;\n done?: boolean;\n};\n\n/**\n * Create a task list block.\n *\n * Markdown:\n * ```\n * - [x] Done item\n * - [ ] Pending item\n * ```\n *\n * @param items - The items of the task list.\n */\nexport function taskList(items: readonly (string | TaskListItem)[]): string {\n const result = [];\n for (const item of items) {\n const text = typeof item === 'string' ? item : item.text;\n const done = typeof item === 'string' ? false : item.done;\n result.push(`- [${done ? 'x' : ' '}] ${text}`);\n }\n\n return result.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;
|
|
1
|
+
{"version":3,"file":"block.mjs","names":["joinBlocks","maxBackticks","prefixLines","horizontalRule","heading","text","options","level","repeat","blockquote","content","alert","type","toUpperCase","codeBlock","language","backticks","Math","max","list","items","map","item","join","orderedList","index","taskList","result","done","push"],"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\nexport type AlertType = 'note' | 'tip' | 'important' | 'warning' | 'caution';\n\n/**\n * Create a GitHub alert (callout) block.\n *\n * Markdown:\n * ```\n * > [!NOTE]\n * > Content\n * ```\n *\n * @param type - The alert type: `note`, `tip`, `important`, `warning` or `caution`.\n * @param content - The content of the alert.\n */\nexport function alert(type: AlertType, content: string | readonly string[]): string {\n return blockquote(`[!${type.toUpperCase()}]\\n${joinBlocks(content)}`);\n}\n\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\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\nexport type TaskListItem = {\n text: string;\n done?: boolean;\n};\n\n/**\n * Create a task list block.\n *\n * Markdown:\n * ```\n * - [x] Done item\n * - [ ] Pending item\n * ```\n *\n * @param items - The items of the task list.\n */\nexport function taskList(items: readonly (string | TaskListItem)[]): string {\n const result = [];\n for (const item of items) {\n const text = typeof item === 'string' ? item : item.text;\n const done = typeof item === 'string' ? false : item.done;\n result.push(`- [${done ? 'x' : ' '}] ${text}`);\n }\n\n return result.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;AAgBA,OAAO,SAASC,KAAKA,CAACC,IAAe,EAAEF,OAAmC,EAAU;EAClF,OAAOD,UAAU,CAAC,KAAKG,IAAI,CAACC,WAAW,CAAC,CAAC,MAAMb,UAAU,CAACU,OAAO,CAAC,EAAE,CAAC;AACvE;AAiBA,OAAO,SAASI,SAASA,CAACJ,OAAe,EAAEJ,OAA0B,EAAU;EAC7E,MAAMS,QAAQ,GAAGT,OAAO,EAAES,QAAQ,IAAI,EAAE;EACxC,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACjB,YAAY,CAACS,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACQ,SAAS,CAAC,GAAGD,QAAQ,GAAG,IAAI,GAAGL,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACQ,SAAS,CAAC;AACzF;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;AAkBA,OAAO,SAASG,QAAQA,CAACN,KAAyC,EAAU;EAC1E,MAAMO,MAAM,GAAG,EAAE;EACjB,KAAK,MAAML,IAAI,IAAIF,KAAK,EAAE;IACxB,MAAMf,IAAI,GAAG,OAAOiB,IAAI,KAAK,QAAQ,GAAGA,IAAI,GAAGA,IAAI,CAACjB,IAAI;IACxD,MAAMuB,IAAI,GAAG,OAAON,IAAI,KAAK,QAAQ,GAAG,KAAK,GAAGA,IAAI,CAACM,IAAI;IACzDD,MAAM,CAACE,IAAI,CAAC,MAAMD,IAAI,GAAG,GAAG,GAAG,GAAG,KAAKvB,IAAI,EAAE,CAAC;EAChD;EAEA,OAAOsB,MAAM,CAACJ,IAAI,CAAC,IAAI,CAAC;AAC1B","ignoreList":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { horizontalRule, heading, blockquote, orderedList, list, codeBlock, taskList } from "./block.mjs";
|
|
1
|
+
export { horizontalRule, heading, blockquote, alert, orderedList, list, codeBlock, taskList } from "./block.mjs";
|
|
2
2
|
export { code, italic, bold, strikethrough, link, image } from "./inline.mjs";
|
|
3
3
|
export { table } from "./table.mjs";
|
|
4
4
|
export { lineBreak, disclosure } from "./html.mjs";
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["horizontalRule","heading","blockquote","orderedList","list","codeBlock","taskList","code","italic","bold","strikethrough","link","image","table","lineBreak","disclosure","escape","joinBlocks"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n horizontalRule,\n heading,\n blockquote,\n orderedList,\n list,\n codeBlock,\n taskList,\n} from './block';\nexport { code, italic, bold, strikethrough, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\nexport type { TaskListItem } from './block';\n"],"mappings":"SACEA,cAAc,EACdC,OAAO,EACPC,UAAU,EACVC,WAAW,EACXC,IAAI,EACJC,SAAS,EACTC,QAAQ;AAAA,SAEDC,IAAI,EAAEC,MAAM,EAAEC,IAAI,EAAEC,aAAa,EAAEC,IAAI,EAAEC,KAAK;AAAA,SAC9CC,KAAK;AAAA,SACLC,SAAS,EAAEC,UAAU;AAAA,SACrBC,MAAM,EAAEC,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["horizontalRule","heading","blockquote","alert","orderedList","list","codeBlock","taskList","code","italic","bold","strikethrough","link","image","table","lineBreak","disclosure","escape","joinBlocks"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n horizontalRule,\n heading,\n blockquote,\n alert,\n orderedList,\n list,\n codeBlock,\n taskList,\n} from './block';\nexport { code, italic, bold, strikethrough, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\nexport type { AlertType, TaskListItem } from './block';\n"],"mappings":"SACEA,cAAc,EACdC,OAAO,EACPC,UAAU,EACVC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,SAAS,EACTC,QAAQ;AAAA,SAEDC,IAAI,EAAEC,MAAM,EAAEC,IAAI,EAAEC,aAAa,EAAEC,IAAI,EAAEC,KAAK;AAAA,SAC9CC,KAAK;AAAA,SACLC,SAAS,EAAEC,UAAU;AAAA,SACrBC,MAAM,EAAEC,UAAU","ignoreList":[]}
|
package/dist/esm/inline.mjs
CHANGED
|
@@ -11,12 +11,12 @@ export function strikethrough(text) {
|
|
|
11
11
|
export function code(text) {
|
|
12
12
|
const backticksCount = maxBackticks(text) + 1;
|
|
13
13
|
const backticks = '`'.repeat(backticksCount);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
return `${backticks}${
|
|
14
|
+
const needsPadding = text.startsWith('`') || text.endsWith('`') || text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text);
|
|
15
|
+
const padding = needsPadding ? ' ' : '';
|
|
16
|
+
return `${backticks}${padding}${text}${padding}${backticks}`;
|
|
17
17
|
}
|
|
18
18
|
export function link(url, text) {
|
|
19
|
-
return
|
|
19
|
+
return `[${text || url}](${url})`;
|
|
20
20
|
}
|
|
21
21
|
export function image(url, text) {
|
|
22
22
|
return ``;
|
package/dist/esm/inline.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline.mjs","names":["maxBackticks","italic","text","bold","strikethrough","code","backticksCount","backticks","repeat","
|
|
1
|
+
{"version":3,"file":"inline.mjs","names":["maxBackticks","italic","text","bold","strikethrough","code","backticksCount","backticks","repeat","needsPadding","startsWith","endsWith","test","padding","link","url","image"],"sources":["../../src/inline.ts"],"sourcesContent":["import { maxBackticks } from './utils';\n\n/**\n * Create an italic text.\n *\n * Markdown: `*text*`\n *\n * @param text - The text to be italicized.\n */\nexport function italic(text: string): string {\n return `*${text}*`;\n}\n\n/**\n * Create a bold text.\n *\n * Markdown: `**text**`\n *\n * @param text - The text to be bolded.\n */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/**\n * Create a strikethrough text.\n *\n * Markdown: `~~text~~`\n *\n * @param text - The text to be struck through.\n */\nexport function strikethrough(text: string): string {\n return `~~${text}~~`;\n}\n\n/**\n * Create a code text.\n *\n * Markdown: `code`\n *\n * @param text - The text to be marked as code.\n */\nexport function code(text: string): string {\n const backticksCount = maxBackticks(text) + 1;\n const backticks = '`'.repeat(backticksCount);\n const needsPadding =\n text.startsWith('`') ||\n text.endsWith('`') ||\n (text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text));\n const padding = needsPadding ? ' ' : '';\n return `${backticks}${padding}${text}${padding}${backticks}`;\n}\n\n/**\n * Create a link span.\n *\n * Markdown: `[text](url)`, or `[url](url)` when `text` is not provided.\n *\n * @param url - The URL to be linked.\n * @param text - The title for the link (optional, defaults to `url`).\n */\nexport function link(url: string, text?: string): string {\n return `[${text || url}](${url})`;\n}\n\n/**\n * Create an image text.\n *\n * Markdown: ``\n *\n * @param url - The URL of the image.\n * @param text - The description for the image (optional).\n */\nexport function image(url: string, text?: string): string {\n return ``;\n}\n"],"mappings":"SAASA,YAAY;AASrB,OAAO,SAASC,MAAMA,CAACC,IAAY,EAAU;EAC3C,OAAO,IAAIA,IAAI,GAAG;AACpB;AASA,OAAO,SAASC,IAAIA,CAACD,IAAY,EAAU;EACzC,OAAO,KAAKA,IAAI,IAAI;AACtB;AASA,OAAO,SAASE,aAAaA,CAACF,IAAY,EAAU;EAClD,OAAO,KAAKA,IAAI,IAAI;AACtB;AASA,OAAO,SAASG,IAAIA,CAACH,IAAY,EAAU;EACzC,MAAMI,cAAc,GAAGN,YAAY,CAACE,IAAI,CAAC,GAAG,CAAC;EAC7C,MAAMK,SAAS,GAAG,GAAG,CAACC,MAAM,CAACF,cAAc,CAAC;EAC5C,MAAMG,YAAY,GAChBP,IAAI,CAACQ,UAAU,CAAC,GAAG,CAAC,IACpBR,IAAI,CAACS,QAAQ,CAAC,GAAG,CAAC,IACjBT,IAAI,CAACQ,UAAU,CAAC,GAAG,CAAC,IAAIR,IAAI,CAACS,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAACC,IAAI,CAACV,IAAI,CAAE;EACnE,MAAMW,OAAO,GAAGJ,YAAY,GAAG,GAAG,GAAG,EAAE;EACvC,OAAO,GAAGF,SAAS,GAAGM,OAAO,GAAGX,IAAI,GAAGW,OAAO,GAAGN,SAAS,EAAE;AAC9D;AAUA,OAAO,SAASO,IAAIA,CAACC,GAAW,EAAEb,IAAa,EAAU;EACvD,OAAO,IAAIA,IAAI,IAAIa,GAAG,KAAKA,GAAG,GAAG;AACnC;AAUA,OAAO,SAASC,KAAKA,CAACD,GAAW,EAAEb,IAAa,EAAU;EACxD,OAAO,KAAKA,IAAI,IAAI,EAAE,KAAKa,GAAG,GAAG;AACnC","ignoreList":[]}
|
package/dist/esm/utils.mjs
CHANGED
|
@@ -15,8 +15,8 @@ export function escape(text) {
|
|
|
15
15
|
export function maxBackticks(text) {
|
|
16
16
|
let max = 0;
|
|
17
17
|
let current = 0;
|
|
18
|
-
for (
|
|
19
|
-
if (
|
|
18
|
+
for (const char of text) {
|
|
19
|
+
if (char === '`') {
|
|
20
20
|
current++;
|
|
21
21
|
max = Math.max(max, current);
|
|
22
22
|
} else {
|
package/dist/esm/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","char","Math"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Join blocks of text into a single markdown document (string).\n *\n * @param blocks - The blocks of text to join.\n * @returns Markdown document string.\n */\nexport function joinBlocks(blocks: string | readonly string[]): string {\n blocks = typeof blocks === 'string' ? [blocks] : blocks;\n\n return blocks.map(trimBlock).filter(Boolean).join('\\n\\n');\n}\n\nfunction trimBlock(block: string): string {\n return block.replace(/^\\n+|\\n+$/g, '');\n}\n\nexport function prefixLines(text: string, prefix: string): string {\n const lines = text.split('\\n');\n return lines.map((line) => `${prefix}${line}`).join('\\n');\n}\n\nexport function escape(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!|<>])/g, '\\\\$1');\n}\n\nexport function maxBackticks(text: string): number {\n let max = 0;\n let current = 0;\n\n for (const char of text) {\n if (char === '`') {\n current++;\n max = Math.max(max, current);\n } else {\n current = 0;\n }\n }\n\n return max;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAUA,CAACC,MAAkC,EAAU;EACrEA,MAAM,GAAG,OAAOA,MAAM,KAAK,QAAQ,GAAG,CAACA,MAAM,CAAC,GAAGA,MAAM;EAEvD,OAAOA,MAAM,CAACC,GAAG,CAACC,SAAS,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,MAAM,CAAC;AAC3D;AAEA,SAASH,SAASA,CAACI,KAAa,EAAU;EACxC,OAAOA,KAAK,CAACC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;AACxC;AAEA,OAAO,SAASC,WAAWA,CAACC,IAAY,EAAEC,MAAc,EAAU;EAChE,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC;EAC9B,OAAOD,KAAK,CAACV,GAAG,CAAEY,IAAI,IAAK,GAAGH,MAAM,GAAGG,IAAI,EAAE,CAAC,CAACR,IAAI,CAAC,IAAI,CAAC;AAC3D;AAEA,OAAO,SAASS,MAAMA,CAACL,IAAY,EAAU;EAC3C,OAAOA,IAAI,CAACF,OAAO,CAAC,4BAA4B,EAAE,MAAM,CAAC;AAC3D;AAEA,OAAO,SAASQ,YAAYA,CAACN,IAAY,EAAU;EACjD,IAAIO,GAAG,GAAG,CAAC;EACX,IAAIC,OAAO,GAAG,CAAC;EAEf,KAAK,MAAMC,IAAI,IAAIT,IAAI,EAAE;IACvB,IAAIS,IAAI,KAAK,GAAG,EAAE;MAChBD,OAAO,EAAE;MACTD,GAAG,GAAGG,IAAI,CAACH,GAAG,CAACA,GAAG,EAAEC,OAAO,CAAC;IAC9B,CAAC,MAAM;MACLA,OAAO,GAAG,CAAC;IACb;EACF;EAEA,OAAOD,GAAG;AACZ","ignoreList":[]}
|
package/dist/types/block.d.ts
CHANGED
|
@@ -27,6 +27,20 @@ export declare function heading(text: string, options?: HeadingOptions): string;
|
|
|
27
27
|
* @param text - The content of the blockquote.
|
|
28
28
|
*/
|
|
29
29
|
export declare function blockquote(content: string | readonly string[]): string;
|
|
30
|
+
export type AlertType = 'note' | 'tip' | 'important' | 'warning' | 'caution';
|
|
31
|
+
/**
|
|
32
|
+
* Create a GitHub alert (callout) block.
|
|
33
|
+
*
|
|
34
|
+
* Markdown:
|
|
35
|
+
* ```
|
|
36
|
+
* > [!NOTE]
|
|
37
|
+
* > Content
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param type - The alert type: `note`, `tip`, `important`, `warning` or `caution`.
|
|
41
|
+
* @param content - The content of the alert.
|
|
42
|
+
*/
|
|
43
|
+
export declare function alert(type: AlertType, content: string | readonly string[]): string;
|
|
30
44
|
type CodeBlockOptions = {
|
|
31
45
|
language?: string;
|
|
32
46
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { horizontalRule, heading, blockquote, orderedList, list, codeBlock, taskList, } from './block';
|
|
1
|
+
export { horizontalRule, heading, blockquote, alert, orderedList, list, codeBlock, taskList, } from './block';
|
|
2
2
|
export { code, italic, bold, strikethrough, link, image } from './inline';
|
|
3
3
|
export { table } from './table';
|
|
4
4
|
export { lineBreak, disclosure } from './html';
|
|
5
5
|
export { escape, joinBlocks } from './utils';
|
|
6
6
|
export type { TableOptions } from './table';
|
|
7
7
|
export type { DisclosureOptions } from './html';
|
|
8
|
-
export type { TaskListItem } from './block';
|
|
8
|
+
export type { AlertType, TaskListItem } from './block';
|
package/dist/types/inline.d.ts
CHANGED
|
@@ -31,14 +31,12 @@ export declare function strikethrough(text: string): string;
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function code(text: string): string;
|
|
33
33
|
/**
|
|
34
|
-
* Create a link
|
|
34
|
+
* Create a link span.
|
|
35
35
|
*
|
|
36
|
-
* Markdown:
|
|
37
|
-
* - `[text](url)` link when `text` is provided
|
|
38
|
-
* - `<url>` autolink when `text` is not provided
|
|
36
|
+
* Markdown: `[text](url)`, or `[url](url)` when `text` is not provided.
|
|
39
37
|
*
|
|
40
38
|
* @param url - The URL to be linked.
|
|
41
|
-
* @param text - The title for the link (optional).
|
|
39
|
+
* @param text - The title for the link (optional, defaults to `url`).
|
|
42
40
|
*/
|
|
43
41
|
export declare function link(url: string, text?: string): string;
|
|
44
42
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-markdown-builder",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Elegant
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Elegant Markdown builder for TypeScript: zero dependencies, tree-shakable, under 1 kB.",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.mjs",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "jest",
|
|
24
24
|
"typecheck": "tsc --noEmit",
|
|
25
|
-
"lint": "
|
|
25
|
+
"lint": "oxlint",
|
|
26
26
|
"clean": "del-cli dist",
|
|
27
|
-
"build": "
|
|
27
|
+
"build": "pnpm clean && pnpm build:commonjs && pnpm build:esm && pnpm build:types",
|
|
28
28
|
"build:commonjs": "BABEL_ENV=cjs babel src --out-dir \"dist/commonjs\" --extensions .js,.ts --out-file-extension .js --source-maps --no-comments",
|
|
29
29
|
"build:esm": "BABEL_ENV=esm babel src --out-dir \"dist/esm\" --extensions .js,.ts --out-file-extension .mjs --source-maps --no-comments",
|
|
30
30
|
"build:types": "tsc --project tsconfig.release.json --outDir \"dist/types\"",
|
|
31
|
-
"format": "
|
|
32
|
-
"format:check": "
|
|
33
|
-
"validate": "
|
|
34
|
-
"validate:fix": "
|
|
31
|
+
"format": "oxfmt",
|
|
32
|
+
"format:check": "oxfmt --check",
|
|
33
|
+
"validate": "pnpm typecheck && pnpm lint && pnpm test && pnpm format:check",
|
|
34
|
+
"validate:fix": "pnpm format && pnpm lint --fix && pnpm typecheck && pnpm test && pnpm build",
|
|
35
35
|
"release": "release-it",
|
|
36
36
|
"release:beta": "release-it --preRelease=beta"
|
|
37
37
|
},
|
|
@@ -50,36 +50,28 @@
|
|
|
50
50
|
"registry": "https://registry.npmjs.org/"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@babel/cli": "^7.
|
|
54
|
-
"@babel/core": "^7.
|
|
55
|
-
"@babel/plugin-
|
|
56
|
-
"@babel/
|
|
57
|
-
"@babel/preset-
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@release-it/conventional-changelog": "^10.0.1",
|
|
61
|
-
"@size-limit/preset-small-lib": "^11.2.0",
|
|
53
|
+
"@babel/cli": "^7.29.7",
|
|
54
|
+
"@babel/core": "^7.29.13",
|
|
55
|
+
"@babel/plugin-transform-modules-commonjs": "^7.29.14",
|
|
56
|
+
"@babel/preset-env": "^7.29.14",
|
|
57
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
58
|
+
"@release-it/conventional-changelog": "^12.0.2",
|
|
59
|
+
"@size-limit/preset-small-lib": "^14.3.0",
|
|
62
60
|
"@types/jest": "^30.0.0",
|
|
63
61
|
"babel-plugin-add-import-extension": "^1.6.0",
|
|
64
|
-
"del-cli": "^
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"prettier": "^3.6.2",
|
|
72
|
-
"release-it": "^19.0.4",
|
|
73
|
-
"typescript": "^5.9.2"
|
|
62
|
+
"del-cli": "^8.0.1",
|
|
63
|
+
"jest": "^30.5.2",
|
|
64
|
+
"oxfmt": "^0.78.0",
|
|
65
|
+
"oxlint": "^1.93.0",
|
|
66
|
+
"release-it": "^21.1.2",
|
|
67
|
+
"size-limit": "^14.3.0",
|
|
68
|
+
"typescript": "^5.9.3"
|
|
74
69
|
},
|
|
75
|
-
"packageManager": "
|
|
70
|
+
"packageManager": "pnpm@12.18.0",
|
|
76
71
|
"engines": {
|
|
77
72
|
"node": ">= 18.0.0"
|
|
78
73
|
},
|
|
79
74
|
"jest": {
|
|
80
|
-
"setupFilesAfterEnv": [
|
|
81
|
-
"<rootDir>/jest-setup.ts"
|
|
82
|
-
],
|
|
83
75
|
"collectCoverageFrom": [
|
|
84
76
|
"src/**/*.{js,jsx,ts,tsx}"
|
|
85
77
|
],
|
|
@@ -90,11 +82,11 @@
|
|
|
90
82
|
"release-it": {
|
|
91
83
|
"hooks": {
|
|
92
84
|
"before:init": [
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
85
|
+
"pnpm typecheck",
|
|
86
|
+
"pnpm test",
|
|
87
|
+
"pnpm lint"
|
|
96
88
|
],
|
|
97
|
-
"after:bump": "
|
|
89
|
+
"after:bump": "pnpm build",
|
|
98
90
|
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
|
|
99
91
|
},
|
|
100
92
|
"git": {
|
|
@@ -138,49 +130,6 @@
|
|
|
138
130
|
}
|
|
139
131
|
}
|
|
140
132
|
},
|
|
141
|
-
"eslintConfig": {
|
|
142
|
-
"root": true,
|
|
143
|
-
"extends": [
|
|
144
|
-
"@callstack/eslint-config/node",
|
|
145
|
-
"prettier"
|
|
146
|
-
],
|
|
147
|
-
"plugins": [
|
|
148
|
-
"import"
|
|
149
|
-
],
|
|
150
|
-
"rules": {
|
|
151
|
-
"prettier/prettier": [
|
|
152
|
-
"error",
|
|
153
|
-
{
|
|
154
|
-
"quoteProps": "consistent",
|
|
155
|
-
"singleQuote": true,
|
|
156
|
-
"tabWidth": 2,
|
|
157
|
-
"trailingComma": "all",
|
|
158
|
-
"useTabs": false
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
"sort-imports": [
|
|
162
|
-
"error",
|
|
163
|
-
{
|
|
164
|
-
"ignoreCase": true,
|
|
165
|
-
"ignoreDeclarationSort": true
|
|
166
|
-
}
|
|
167
|
-
],
|
|
168
|
-
"import/order": "error"
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
"eslintIgnore": [
|
|
172
|
-
"node_modules/",
|
|
173
|
-
"dist/",
|
|
174
|
-
"coverage/",
|
|
175
|
-
"website/"
|
|
176
|
-
],
|
|
177
|
-
"prettier": {
|
|
178
|
-
"quoteProps": "consistent",
|
|
179
|
-
"singleQuote": true,
|
|
180
|
-
"tabWidth": 2,
|
|
181
|
-
"trailingComma": "all",
|
|
182
|
-
"useTabs": false
|
|
183
|
-
},
|
|
184
133
|
"size-limit": [
|
|
185
134
|
{
|
|
186
135
|
"path": "./dist/esm/index.mjs",
|