Function md

Properties

bold: ((text: InlineText<BoldInnerMarks>) => BoldMark)

Type declaration

    • (text): BoldMark
    • Creates bold text.

      Parameters

      Returns BoldMark

      bold mark

      bold('this is important')
      
      bold(md`important text with ${italic('extra formatting')}`)
      
code: ((text: string) => CodeMark)

Type declaration

    • (text): CodeMark
    • Creates inline code.

      Parameters

      • text: string

        source code as plain string

      Returns CodeMark

      code mark

      code('console.log("Hello, world!")')
      
codeBlock: {
    (text: string): CodeBlock;
    (lang: string, text: string): CodeBlock;
}

Type declaration

    • (text): CodeBlock
    • Creates code block, without any syntax highlighting.

      Parameters

      • text: string

        source as plain string (may be multiline)

      Returns CodeBlock

      code block

      codeBlock('npm install build-md')
      

      MarkdownDocument.code

    • (lang, text): CodeBlock
    • Creates code block with syntax highlighting.

      Parameters

      • lang: string

        programming language for syntax highlighting

      • text: string

        source as plain string (may be multiline)

      Returns CodeBlock

      code block

      codeBlock('ts', `function greet(name: string): void {
      console.log('Hello, ' + name + '!');
      }`)

      MarkdownDocument.code

details: {
    (text: BlockText): DetailsBlock;
    (summary: InlineText, text: BlockText): DetailsBlock;
}

Type declaration

    • (text): DetailsBlock
    • Creates expandable details element, without custom summary text.

      Not part of Markdown syntax, relies on support for HTML rendering.

      Parameters

      • text: BlockText

        plain string or text with inline or block formatting

      Returns DetailsBlock

      details block

      details('text hidden until expanded')
      
      details(md`text with ${bold('inline')} and ${list(['block'])} elements.`)
      

      MarkdownDocument.details

    • (summary, text): DetailsBlock
    • Creates expandable details element with custom summary text.

      Not part of Markdown syntax, relies on support for HTML rendering.

      Parameters

      • summary: InlineText

        plain string or text with inline formatting

      • text: BlockText

        plain string or text with inline or block formatting

      Returns DetailsBlock

      details block

      details('summary text always shown', 'text hidden until expanded')
      details(
      md`summary text with ${italic('inline')} formatting`,
      md`text with ${bold('inline')} and ${list(['block'])} elements.`
      )

      MarkdownDocument.details method

footnote: ((text: InlineText, label?: string) => FootnoteMark)

Type declaration

    • (text, label?): FootnoteMark
    • Creates footnote label and registers content to be appended to document.

      Footnotes allow you to add notes and references without cluttering the body of the document. When you create a footnote, a superscript number with a link appears where you added the footnote reference. Readers can click the link to jump to the content of the footnote at the bottom of the page.

      Parameters

      • text: InlineText

        plain string or text with inline formatting

      • Optionallabel: string

        custom label for footnote link (default is auto-incremented number)

      Returns FootnoteMark

      footnote mark

      foonote('more info')
      
      footnote(md`more info with ${bold('extra formatting')}`)
      
      foonote('more info', 'customLabel')
      
heading: ((level: HeadingLevel, text: InlineText) => HeadingBlock)

Type declaration

image: ((src: string, alt: string) => ImageMark)

Type declaration

    • (src, alt): ImageMark
    • Creates image element.

      Parameters

      • src: string

        image URL

      • alt: string

        alternative text when image cannot be displayed

      Returns ImageMark

      image mark

      image('./images/logo.png', 'Logo')
      
italic: ((text: InlineText<ItalicInnerMarks>) => ItalicMark)

Type declaration

    • (text): ItalicMark
    • Creates italic text.

      Parameters

      Returns ItalicMark

      italic mark

      italic('emphasize this')
      
      italic(md`emphasize this with ${bold('extra formatting')}`)
      
link: ((href: string, text?: InlineText<LinkInnerMarks>, title?: string) => LinkMark)

Type declaration

    • (href, text?, title?): LinkMark
    • Creates link element.

      Parameters

      • href: string

        link URL

      • Optionaltext: InlineText<LinkInnerMarks>

        display text for link (defaults to URL)

      • Optionaltitle: string

        tooltip when hovering over the link

      Returns LinkMark

      link mark

      link('https://www.markdownguide.org/')
      
      link('https://www.markdownguide.org/', 'Markdown Guide')
      
      link('https://www.markdownguide.org/', 'this guide', 'Markdown Guide')
      
list: {
    (items: BlockText[]): UnorderedListBlock;
    (kind: "unordered", items: BlockText[]): UnorderedListBlock;
    (kind: "ordered", items: BlockText[]): OrderedListBlock;
    (kind: "task", items: [boolean, BlockText][]): TaskListBlock;
}

Type declaration

    • (items): UnorderedListBlock
    • Creates unordered list.

      Parameters

      • items: BlockText[]

        array of items, each of which may contain block or inline formatting

      Returns UnorderedListBlock

      unordered list block

      list(['first item', 'second item'])
      
      list([
      md`first item with ${italic('text formatting')}`,
      md`second item with nested list:${list([
      "second item's first item",
      "second item's second item"
      ])}`
      ])

      MarkdownDocument.list

    • (kind, items): UnorderedListBlock
    • Creates unordered list.

      Parameters

      • kind: "unordered"

        type of list (may be ommitted since 'unordered' is the default)

      • items: BlockText[]

        array of items, each of which may contain block or inline formatting

      Returns UnorderedListBlock

      unordered list block

      list('unordered' ['first item', 'second item'])
      
      list('unordered', [
      md`first item with ${italic('text formatting')}`,
      md`second item with nested list:${list('unordered', [
      "second item's first item",
      "second item's second item"
      ])}`
      ])

      MarkdownDocument.list

    • (kind, items): OrderedListBlock
    • Creates ordered list.

      Parameters

      • kind: "ordered"

        type of list

      • items: BlockText[]

        array of items (without numbers), each of which may contain block or inline formatting

      Returns OrderedListBlock

      ordered list block

      list('ordered' ['first item', 'second item'])
      
      list('ordered', [
      md`first item with ${italic('text formatting')}`,
      md`second item with nested list:${list('ordered', [
      "second item's first item",
      "second item's second item"
      ])}`
      ])

      MarkdownDocument.list

    • (kind, items): TaskListBlock
    • Creates task list (also known as checklist or todo list).

      Part of extended Markdown syntax, not supported by all Markdown processors.

      Parameters

      • kind: "task"

        type of list

      • items: [boolean, BlockText][]

        array of items, each of which is a tuple of checked state and text (plain or with formatting)

      Returns TaskListBlock

      task list block

      list('task', [[true, 'first task is done'], [false, 'second task is done']])
      

      MarkdownDocument.list

paragraph: ((text: BlockText) => ParagraphBlock)

Type declaration

quote: ((text: BlockText) => QuoteBlock)

Type declaration

    • (text): QuoteBlock
    • Creates quote block.

      Parameters

      • text: BlockText

        plain string or text with inline or block formatting

      Returns QuoteBlock

      quote block

      quote('Some quoted text.')
      
      quote(md`Some quoted text with ${bold('formatting')}.`)
      

      MarkdownDocument.quote

rule: (() => RuleBlock)

Type declaration

Type declaration

    • (text): StrikethroughMark
    • Creates strikethrough text - rendered with horizontal line through the middle.

      Parameters

      Returns StrikethroughMark

      strikethrough mark

      strikethrough('cross this out')
      
      strikethrough(md`cross out this text with ${italic('extra formatting')}`)
      
table: ((columns: TableColumn[], rows: TableRow[]) => TableBlock)

Type declaration

    • (columns, rows): TableBlock
    • Creates table.

      Part of extended Markdown syntax, not supported by all Markdown processors.

      Parameters

      • columns: TableColumn[]

        table header - column heading texts with optional column alignments

      • rows: TableRow[]

        table body - rows with text content for column cells

      Returns TableBlock

      table block

      table(['x', 'y'], [['0', '0'], ['5', '20']])
      
      table(
      [
      { heading: 'Error', alignment: 'left' },
      { heading: link('./environments.md', 'Environment'), alignment: 'center' },
      { heading: 'Occurrences', alignment: 'right' },
      ],
      [
      [
      code("TypeError: Cannot read properties of undefined (reading 'push')"),
      'production',
      '19',
      ],
      [
      code("TypeError: Cannot read properties of null (reading '0')"),
      'staging',
      '5',
      ],
      ]
      )

      MarkdownDocument.table