Navigate to:
- Creating an Instance
- Paragraphs
- Headings
- Blockquotes
- Horizontal Rule
- Code Blocks
- Tables
- Line Breaks
- Inline Code
- Inline Formatting
- Links
- Images
- Getting the Markdown
- Line Indentation
- Single Line
- Bulleted Lists
- Ordered Lists
- Collapsible Sections
- Badge
You can install MarkdownWizard either through npm or unpkg.
npm install markdown-wizard
<script src="https://www.unpkg.com/markdown-wizard@1.0.3/main.js"></script>Usage when installed with UNPKG
<script>
const wiz = new sk.MarkdownWizard()
wiz.h1("Rest is up to you :)")
</script>To get started with the MarkdownWizard, create a new instance:
const builder = new MarkdownWizard();Description: Creates a new instance of the MarkdownWizard class.
You can add paragraphs of text using the p(text) method:
builder.p("This is a paragraph of text.");Description: Appends a paragraph of text to the Markdown content with the specified text.
Parameters:
| Parameter | Description |
|---|---|
text |
The text to add as a paragraph. |
You can add headings using the h1(header, underline, level), h2(header, underline, level), and h3(header) methods:
builder.h1("Heading 1");Description: Appends a level 1 heading to the Markdown content with the specified header.
Parameters:
| Parameter | Description |
|---|---|
header |
The header text. |
underline (optional) |
Whether to underline the header (default is false). |
level (optional) |
The indentation level (default is 0). |
builder.h2("Heading 2");Description: Appends a level 2 heading to the Markdown content with the specified header.
Parameters:
| Parameter | Description |
|---|---|
header |
The header text. |
underline (optional) |
Whether to underline the header (default is false). |
level (optional) |
The indentation level (default is 0). |
builder.h3("Heading 3");Description: Appends a level 3 heading to the Markdown content with the specified header.
Parameters:
| Parameter | Description |
|---|---|
header |
The header text. |
You can add blockquotes using the blockquote(text) method:
builder.blockquote("This is a blockquote.\nIt can have multiple lines.");Don't love what you do, do what you love. - SK.
Description: Appends a blockquote to the Markdown content with the specified text.
Parameters:
| Parameter | Description |
|---|---|
text |
The blockquote text. |
You can add a horizontal rule using the hr() method:
builder.hr();Description: Appends a horizontal rule (hr) to the Markdown content.
You can add code blocks using the codeBlock(code, lang) method:
builder.codeBlock("const x = 10;\nconsole.log(x);", "javascript");Description: Appends a code block to the Markdown content with the specified code and optional lang (language) identifier.
Parameters:
| Parameter | Description |
|---|---|
code |
The code to be included in the code block. |
lang (optional) |
The language identifier for syntax highlighting (default is an empty string). |
You can add tables using the table(columns, rows, alignments) method:
const columns = ["Header 1", "Header 2"];const rows = [["Row 1 Cell 1", "Row 1 Cell 2"], ["Row 2 Cell 1", "Row 2 Cell 2"]];const alignments = [Alignment.LEFT, Alignment.RIGHT];builder.table(columns, rows, alignments);Description: Appends a table to the Markdown content with specified columns, rows, and optional alignments for each column.
Parameters:
| Parameter | Description |
|---|---|
columns |
An array of column headers. |
rows |
An array of arrays representing table rows. |
alignments (optional) |
An array of text alignment options for columns. Alignments can be Alignment.LEFT, Alignment.CENTER, or Alignment.RIGHT. |
You can add a line break using the br() method:
builder.br();Description: Adds a line break to the Markdown content.
You can format text as inline code using the inlineCode(code) method:
const inlineCodeText = builder.inlineCode("console.log('Hello, World!');");Description: Formats text as inline code by wrapping it in backticks (code).
Parameters:
| Parameter | Description |
|---|---|
code |
The text to be formatted as inline code. |
You can format text as italic or bold using the inlineItalic(string) and inlineBold(string) methods:
const italicText = builder.inlineItalic("This is italic text.");const boldText = builder.inlineBold("This is bold text.");Description: Formats text as italic or bold by enclosing it in asterisks (*) or double asterisks (**).
Parameters:
| Parameter | Description |
|---|---|
string |
The text to be formatted as italic or bold. |
You can create links using the link(url, text, title) method:
const linkText = builder.link("https://example.com", "Visit Example", "Go to Example Website");Description: Creates a hyperlink with the specified url, text, and optional title.
Parameters:
| Parameter | Description |
|---|---|
url |
The URL to link to. |
text |
The link text. |
title (optional) |
The optional link title. |
You can insert images using the image(url, altText, title) method:
const imageTag = builder.image("https://example.com/image.jpg", "Alt Text", "Image Title");Description: Inserts an image into the Markdown content with the specified url, altText, and optional title.
Parameters:
| Parameter | Description |
|---|---|
url |
The URL of the image. |
altText |
The alternative text for the image. |
title (optional) |
The optional image title. |
To retrieve the generated Markdown content, use the getMarkdown() method:
const markdown = builder.getMarkdown();Description: Returns the generated Markdown content as a string.
You can control line indentation using the write(string, level) and writeln(string, level) methods. The level parameter determines the number of spaces to indent:
builder.writeln("Indented Text", 1);Description: Appends a line of text followed by a line break. The level parameter controls the indentation level.
Parameters:
| Parameter | Description |
|---|---|
string |
The text to append. |
level (optional) |
The indentation level (default is 0). |
You can remove extra spaces and convert multiple lines into a single line using the singleLine(string) method:
const input = " This is\na\nmultiline\n text. ";const singleLineText = builder.singleLine(input);Description: Trims and removes extra spaces from a string to make it a single line.
Parameters:
| Parameter | Description |
|---|---|
string |
The input string. |
You can create bulleted lists using the bulletedList(list, levels) method:
const list = ["Item 1", "Item 2", "Item 3"];builder.bulletedList(list);Description: Appends a bulleted list to the Markdown content from an array of items.
Parameters:
| Parameter | Description |
|---|---|
list |
An array of items to be listed in the bulleted list. |
levels (optional) |
An optional array of indentation levels for each item. |
You can create ordered (numbered) lists using the orderedList(list) method:
const orderedListItems = ["First Item", "Second Item", "Third Item"];builder.orderedList(orderedListItems);Description: Appends an ordered (numbered) list to the Markdown content from an array of items.
Parameters:
| Parameter | Description |
|---|---|
list |
An array of items to be listed in the ordered list. |
You can create collapsible sections using the collapsible(title, initiallyCollapsed, level) and endCollapsible() methods:
builder.collapsible("Click to Expand", true);Description: Starts a collapsible section in the Markdown content with the specified title. You can choose to make it initially collapsed or expanded by setting initiallyCollapsed. The level parameter controls the indentation level.
Parameters:
| Parameter | Description |
|---|---|
title |
The title of the collapsible section. |
initiallyCollapsed (optional) |
Whether the section is initially collapsed (default is false). |
level (optional) |
The indentation level (default is 0). |
builder.endCollapsible();Description: Ends the current collapsible section in the Markdown content.
You can add badges to your Markdown content using the badge(type, ...params) method:
builder.badge("BuyMeACoffee", "your-username");builder.badge("GitHub", "your-username", "your-repo");builder.badge("Twitter", "your-twitter-username");Description: Adds a badge to the Markdown content for various services like BuyMeACoffee, GitHub, and Twitter.
Parameters:
| Parameter | Description |
|---|---|
type |
The type of badge (e.g., 'BuyMeACoffee', 'GitHub', 'Twitter'). |
params |
Parameters specific to the badge type. |