Every function is pure and returns a string. You can compose them by passing one function's output as input to another.
import { heading, bold, joinBlocks } from 'ts-markdown-builder';heading('Title'); // # Title
heading('Title', { level: 2 }); // ## TitleMarkdown heading (#, ##, etc.).
heading(text: string, options?: { level?: number }): stringtext— Heading textoptions.level— Heading level (1-6). Default:1
blockquote('Hello');
// > Hello
blockquote(['Paragraph 1', 'Paragraph 2']);
// > Paragraph 1
// >
// > Paragraph 2Blockquote block. Accepts a string or an array of strings (joined as separate blocks).
blockquote(content: string | readonly string[]): stringcontent— Blockquote content
codeBlock('const x = 1;', { language: 'ts' });
// ```ts
// const x = 1;
// ```Fenced code block. The backtick fence adjusts automatically when the content contains backticks.
codeBlock(content: string, options?: { language?: string }): stringcontent— Code contentoptions.language— Language identifier for syntax highlighting. Default:''
list(['Apples', 'Oranges']);
// - Apples
// - OrangesUnordered (bullet) list.
list(items: readonly string[]): stringitems— List items
orderedList(['First', 'Second']);
// 1. First
// 2. SecondOrdered (numbered) list.
orderedList(items: readonly string[]): stringitems— List items
taskList([
{ text: 'Buy milk', done: true },
'Write docs',
]);
// - [x] Buy milk
// - [ ] Write docsGFM task list with checkboxes. Items can be plain strings (unchecked by default) or TaskListItem objects.
taskList(items: readonly (string | TaskListItem)[]): stringitems— Task list items (strings orTaskListItemobjects)
TaskListItem
interface TaskListItem {
text: string;
done?: boolean;
}text— Item textdone— Whether the item is checked. Default:false
horizontalRule; // ---Horizontal rule constant. Not a function -- use it directly.
bold('important'); // **important**Bold text (**...**).
bold(text: string): stringtext— Text to bold
italic('emphasis'); // *emphasis*Italic text (*...*).
italic(text: string): stringtext— Text to italicize
strikethrough('removed'); // ~~removed~~GFM strikethrough text (~~...~~).
strikethrough(text: string): stringtext— Text to strike through
code('foo'); // `foo`Inline code span. Backtick count and spacing adjust automatically when the text itself contains backticks.
code(text: string): stringtext— Text to mark as code
link('https://example.com', 'Example'); // [Example](https://example.com)
link('https://example.com'); // <https://example.com>Link or autolink. Without text, produces an autolink (<url>).
link(url: string, text?: string): stringurl— Link URLtext— Optional link text
image('photo.png', 'A photo'); // 
image('photo.png'); // Image ().
image(url: string, text?: string): stringurl— Image URLtext— Optional alt text
table(
['Name', 'Age'],
[
['Alice', '30'],
['Bob', '25'],
],
);
// | Name | Age |
// | ----- | --- |
// | Alice | 30 |
// | Bob | 25 |
table(
['A', 'B'],
[
['1', '2'],
],
{ compact: true },
);
// | A | B |
// | - | - |
// | 1 | 2 |GFM table. Pipe characters and newlines in cell content are escaped automatically. Returns '' if header is empty.
table(
header: readonly string[],
rows: readonly string[][],
options?: TableOptions,
): stringheader— Column headersrows— Table rowsoptions.compact— Whentrue, skips column-width padding. Default:false
TableOptions
interface TableOptions {
compact?: boolean;
}compact— Disable column-width alignment padding. Default:false
disclosure('Click me', 'Hidden content');
// <details>
// <summary>Click me</summary>
//
// Hidden content
//
// </details>
disclosure('Details', 'Body', { open: true });
// <details open>
// <summary>Details</summary>
//
// Body
//
// </details>HTML <details>/<summary> block. Content is wrapped with blank lines so markdown inside it renders correctly.
disclosure(title: string, content: string, options?: DisclosureOptions): stringtitle— Summary text (plain text or markdown heading)content— Disclosure body (can contain markdown)options.open— Whether the block is open by default. Default:false
DisclosureOptions
interface DisclosureOptions {
open?: boolean;
}open— Render with theopenattribute. Default:false
lineBreak; // '<br/>'HTML line break constant. Not a function -- use it directly.
joinBlocks([
heading('Title'),
list(['A', 'B']),
'Some text',
]);
// # Title
//
// - A
// - B
//
// Some text'Joins blocks with double newlines (a blank line between each). Trims leading/trailing newlines per block and drops empty ones. Accepts a single string or an array.
joinBlocks(blocks: string | readonly string[]): stringblocks— Blocks to join
escape('**not bold**'); // \\*\\*not bold\\*\\*Escapes markdown special characters (\ ` * _ { } [ ] ( ) # + - . ! | < >).
escape(text: string): stringtext— Text to escape
TableOptions— Options fortable()DisclosureOptions— Options fordisclosure()TaskListItem— Item shape fortaskList()