Creates instance for building a Markdown document.
Optional
options: MarkdownDocumentOptionsCustomization options (e.g. mutability).
Add all blocks from another document.
Useful for reusing code.
other document
document extended by additional blocks
Add all blocks from multiple other documents.
Useful for reusing code.
Rest
...documents: Conditional<MarkdownDocument>[]other documents
document extended by additional blocks
const intro = new MarkdownDocument().heading(1, 'Main title').paragraph('Some text.')
const chapter1 = new MarkdownDocument().heading(2, 'Chapter title').paragraph('Some text.')
const chapter2 = new MarkdownDocument().heading(2, 'Chapter title').paragraph('Some text.')
const conclusion = new MarkdownDocument().heading(2, 'Conclusion').paragraph('Some text.')
new MarkdownDocument()
.$concat(intro, chapter1, chapter2, conclusion)
Iteratively adds element to document using callback function.
Convenient when multiple elements need be added dynamically per item in array.
array of items to be iterated over
callback invoked for every item in items, receives current document and should return modified document
document with additional blocks from each array item
Conditionally adds elements to document using callback function.
Convenient when multiple elements are subject to same conditional logic.
boolean predicate - if true
then ifFn is used, if false
then either elseFn is used or nothing is changed
callback used when condition is true
, receives current document and should return modified document
Optional
elseFn: ((document: MarkdownDocument) => MarkdownDocument)optional callback used when condition is false
, receives current document and should return modified document
document with or without additional blocks based on condition
Adds code block to document (unless empty), without any syntax highlighting.
source as plain string (may be multiline)
document with additional code block
Adds code block to document (unless empty), with syntax highlighting.
programming language for syntax highlighting
source as plain string (may be multiline)
document with additional code block
Adds expandable details element (unless empty) to document, without custom summary text.
Not part of Markdown syntax, relies on support for HTML rendering.
plain string, text with inline or block formatting, or another document
document with additional details block
Adds expandable details element (unless empty) to document, with custom summary text.
Not part of Markdown syntax, relies on support for HTML rendering.
plain string or text with inline formatting
plain string, text with inline or block formatting, or another document
document with additional details block
new MarkdownDocument()
.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.`
)
md.details method
Adds heading to document (unless empty).
heading level
plain string or text with inline formatting
document with additional heading block
Adds unordered list to document (unless empty).
array of items, each of which may contain block or inline formatting
document with additional unordered list block
Adds unordered list to document (unless empty).
type of list (may be ommitted since 'unordered'
is the default)
array of items, each of which may contain block or inline formatting
document with additional unordered list block
Adds ordered list to document (unless empty).
type of list
array of items, each of which may contain block or inline formatting
document with additional ordered list block
Adds task list to document (unless empty). Also known as checklist or todo list.
Part of extended Markdown syntax, not supported by all Markdown processors.
type of list
array of items, each of which is a tuple of checked state and text (plain or with formatting)
document with additional task list block
Adds paragraph to document (unless empty).
plain string or text with inline or block formatting
document with additional paragraph block
Adds quote block to document (unless empty).
plain string or text with inline or block formatting
document with additional quote block
Adds horizontal rule to document.
document with additional rule block
Adds table to document (unless no columns).
Part of extended Markdown syntax, not supported by all Markdown processors.
table header - column heading texts with optional column alignments
table body - rows with text content for column cells
document with additional table block
new MarkdownDocument().table(['x', 'y'], [['0', '0'], ['5', '20']])
new MarkdownDocument().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',
],
]
)
Builder for Markdown documents.
See
md for creating inline Markdown texts