md-utils-ts
Tiny markdown utility functions for Typescript.
Install
Install with npm:
$ npm install --save md-utils-ts
Usage
See Implementation for details.
import md, { bold } from "md-utils-ts";
const boldText = bold("some text");
console.log(boldText);
const italicText = md.italic("Hello, world!");
console.log(italicText);
API
Note: Table is not supported. You can use markdown-table as well.
bold
Make the text bold.
Parameters:
text
(string): The input text.
Example:
const result = bold("Hello, world!");
italic
Make the text italic.
Parameters:
text
(string): The input text.
Example:
const result = italic("Hello, world!");
del
Add strike-through to the text.
Parameters:
text
(string): The input text.
Example:
const result = del("Hello, world!");
underline
Add underline to the text.
Parameters:
text
(string): The input text.
Example:
const result = underline("Hello, world!");
anchor
Create an anchor link.
Parameters:
text
(string): The anchor text.href
(string): The URL to link to.
Example:
const result = anchor("OpenAI", "https://www.openai.com");
code
Create a code block or inline code.
Parameters:
inline
(boolean): Whether the code should be inline or in a block.language
(string): The code language for syntax highlighting.text
(string): The code content.
Example:
const tsCodeBlock = code(false)("ts");
const result = tsCodeBlock("console.log('Hello, world!');");
inlineCode
Create inline code with optional syntax highlighting.
Parameters:
text
(string): The code content.
Example:
const code = inlineCode("console.log('Hello, world!');");
codeBlock
Create a code block with optional syntax highlighting.
Parameters:
language
(string, optional): The code language for syntax highlighting.text
(string): The code content.
Example:
const code = codeBlock("ts")("console.log('Hello, world!');");
equation
Create an equation block or inline equation.
Parameters:
inline
(boolean): Whether the equation should be inline or in a block.text
(string): The equation content.
Example:
const equationBlock = equation(false)("x^2 + y^2 = z^2");
const inlineEquation = equation(true)("E = mc^2");
inlineEquation
Create inline code with optional syntax highlighting.
Parameters:
text
(string): The equation content.
Example:
const result = inlineEquation("E = mc^2");
equationBlock
Create an equation block or inline equation.
Parameters:
text
(string): The equation content.
Example:
const result = equationBlock("x^2 + y^2 = z^2");
h
Create a heading with the specified level.
Parameters:
level
(number): The level of the heading (1 to 6).text
(string): The heading text.
Example:
const heading = h(2)("Hello, world!");
h1
Create a level 1 heading.
Parameters:
text
(string): The heading text.
Example:
const heading = h1("Title");
h2
Create a level 2 heading.
Parameters:
text
(string): The heading text.
Example:
const heading = h2("Subtitle");
h3
Create a level 3 heading.
Parameters:
text
(string): The heading text.
Example:
const heading = h3("Subsection");
h4
Create a level 4 heading.
Parameters:
text
(string): The heading text.
Example:
const heading = h4("Subsubsection");
h5
Create a level 5 heading.
Parameters:
text
(string): The heading text.
Example:
const heading = h5("Subsubsubsection");
h6
Create a level 6 heading.
Parameters:
text
(string): The heading text.
Example:
const heading = h6("Subsubsubsubsection");
quote
Convert text to a blockquote.
Parameters:
text
(string): The input text.
Example:
const quotedText = quote("This is a quoted text.");
bullet
Create a bullet point list item.
Parameters:
text
(string): The content of the bullet point.count
(number, optional): The optional index/count of the bullet point.
Example:
const bulletPoint = bullet("List item");
const numberedBulletPoint = bullet("List item", 1);
todo
Create a todo list item.
Parameters:
text
(string): The content of the todo item.checked
(boolean): Whether the todo item is checked or not.
Example:
const uncheckedTodo = todo("Task to be done", false);
const checkedTodo = todo("Completed task", true);
image
Create an image element.
Parameters:
alt
(string): The alt text for the image.href
(string): The URL of the image.
Example:
const imageElement = image("Description", "https://example.com/image.jpg");
divider
Create a horizontal divider.
Example:
const dividerElement = divider();
details
Create a collapsible details element.
Parameters:
summary
(string): The summary text for the details element.details
(string): The details/content of the details element.
Example:
const detailsElement = details("Click to expand", "Hidden content");
sup
Create a superscript text.
Parameters:
text
(string): The input text.
Example:
const superscriptText = sup("2");
sub
Create a subscript text.
Parameters:
text
(string): The input text.
Example:
const subscriptText = sub("2");
indent
Indent the text with a specified number of spaces.
Parameters:
space
(number, default: 2): The number of spaces to indent with.text
(string): The input text.level
(number, default: 1): The level of indentation.
Example:
const indentedText = indent(4)("Indented text", 2);