Just simple markdown utils!
Important
This project is under development.
Any sequence of characters is a valid CommonMark (Markdown) document.
Markdown is intended to be as easy-to-read and easy-to-write as is. Readability is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text. (from John Gruber creator of Makrdown).
While Markdown is designed to be simple, I often find myself in situations where there is simply no tool to allow programmatically working with Markdown syntax without dealing with complex and strict AST objects and choosing between dozens of available tools and extensions. Often, not even worth pursuing ideas around Markdown.
The idea is to make good-enough tools to read and write Markdown programmatically, as easy as Markdown itself is, without dealing with an AST.
Install package:
# npm
npm install omark
# yarn
yarn add omark
# pnpm
pnpm install omark
# bun
bun install omark
Import:
// ESM
import { md } from "omark";
// CommonJS
const { md } = require("omark");
Render a markdown blockquote text with > in front of a paragraph
Example:
md.blockquote("Hello, World!");
// => "> Hello, World!"
Render a markdown bold text.
Example:
md.bold("Hello, World!");
// => "**Hello, World!**"
Render a markdown bold and italic text.
Example:
md.bold("Hello, World!");
// => "***Hello, World!***"
Format a string as a code block.
Example:
md.codeBlock('console.log("Hello, World!");', "js");
// => "```js\nconsole.log("Hello, World!");\n```"
Render a markdown heading.
Example:
md.heading(1, "Hello, World!");
// => "\n# Hello, World!\n"
Render a markdown horizontal rule.
Example:
md.hr();
// => "---"
Render a markdown image.
Example:
md.image("https://cataas.com/cat", "Cute Cat");
// => "![Cute Cat](https://cataas.com/cat)"
Render a markdown italic text.
Example:
md.bold("Hello, World!");
// => "_Hello, World!_"
Render a markdown link.
Example:
md.link("https://www.google.com", "Google");
// => "[Google](https://www.google.com)"
md.link("https://www.google.com", "Google", { external: true });
// => "<a href="https://www.google.com" title="Google" target="_blank">Google</a>"
Render a markdown ordered or unordered list.
Example:
md.list(["Item 1", "Item 2", "Item 3"]);
// => "- Item 1\n- Item 2\n- Item 3"
md.list(["Item 1", "Item 2", "Item 3"], { ordered: true });
// => "1. Item 1\n2. Item 2\n3. Item 3")
Render a markdown strikethrough text.
Example:
md.strikethrough("Hello, World!");
// => "~~Hello, World!~~"
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Made with 💛
Published under MIT License.