1.0.3 • Published 7 months ago

markdown-wizard v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

MarkdownWizard Documentation


Navigate to:

Installing

You can install MarkdownWizard either through npm or unpkg.

With NPM

npm install markdown-wizard

With UNPKG

<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>

Creating an Instance

To get started with the MarkdownWizard, create a new instance:

const builder = new MarkdownWizard();

Description: Creates a new instance of the MarkdownWizard class.

Paragraphs

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:

ParameterDescription
textThe text to add as a paragraph.

Headings

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:

ParameterDescription
headerThe 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:

ParameterDescription
headerThe 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:

ParameterDescription
headerThe header text.

Blockquotes

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:

ParameterDescription
textThe blockquote text.

Horizontal Rule

You can add a horizontal rule using the hr() method:

builder.hr();

Description: Appends a horizontal rule (hr) to the Markdown content.

Code Blocks

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:

ParameterDescription
codeThe code to be included in the code block.
lang (optional)The language identifier for syntax highlighting (default is an empty string).

Tables

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:

ParameterDescription
columnsAn array of column headers.
rowsAn 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.

Line Breaks

You can add a line break using the br() method:

builder.br();

Description: Adds a line break to the Markdown content.

Inline Code

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:

ParameterDescription
codeThe text to be formatted as inline code.

Inline Formatting

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:

ParameterDescription
stringThe text to be formatted as italic or bold.

Links

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:

ParameterDescription
urlThe URL to link to.
textThe link text.
title (optional)The optional link title.

Images

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:

ParameterDescription
urlThe URL of the image.
altTextThe alternative text for the image.
title (optional)The optional image title.

Getting the Markdown

To retrieve the generated Markdown content, use the getMarkdown() method:

const markdown = builder.getMarkdown();

Description: Returns the generated Markdown content as a string.

Line Indentation

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:

ParameterDescription
stringThe text to append.
level (optional)The indentation level (default is 0).

Single Line

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:

ParameterDescription
stringThe input string.

Bulleted Lists

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:

ParameterDescription
listAn array of items to be listed in the bulleted list.
levels (optional)An optional array of indentation levels for each item.

Ordered Lists

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:

ParameterDescription
listAn array of items to be listed in the ordered list.

Collapsible Sections

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:

ParameterDescription
titleThe 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.

Badge

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:

ParameterDescription
typeThe type of badge (e.g., 'BuyMeACoffee', 'GitHub', 'Twitter').
paramsParameters specific to the badge type.