Markdown Utilities for TypeScript

2.0.0 · active · verified Tue Apr 21

`md-utils-ts` is a lightweight, TypeScript-first utility library designed for programmatic generation of common Markdown syntax elements. Currently at version 2.0.0, it provides a focused collection of functions to create bold text, italics, strikethroughs, underlines, anchor links, code blocks (inline and multi-line), equations, and headings (H1-H6). The library emphasizes simplicity and type safety, offering both individual named exports for each utility (e.g., `bold`, `h1`) and a bundled `md` object for convenience (e.g., `md.italic`). Unlike comprehensive Markdown parsers or renderers, `md-utils-ts` strictly focuses on outputting valid Markdown strings, making it ideal for scenarios where you need to construct Markdown content dynamically without heavy dependencies. Its release cadence is likely stable, with updates driven by new Markdown syntax needs or minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing both the default `md` object and named utility functions to create various Markdown elements like headings, bold text, links, code blocks, and equations.

import md, { bold, h1, anchor, codeBlock, equationBlock } from "md-utils-ts";

// Create a main heading
const title = h1("Welcome to md-utils-ts!");

// Bold and italic text using individual exports and the 'md' object
const importantText = bold("This text is important.") + " " + md.italic("And this is emphasized.");

// Create an anchor link
const githubLink = anchor("md-utils-ts GitHub", "https://github.com/TomPenguin/md-utils-ts");

// Generate a TypeScript code block
const tsExample = codeBlock("typescript")(`
function greet(name: string): string {
  return \`Hello, \${name}!\`;
}
console.log(greet("World"));
`);

// Create an equation block
const pythagoreanTheorem = equationBlock("a^2 + b^2 = c^2");

console.log(title);
console.log(importantText);
console.log(githubLink);
console.log("\n--- TypeScript Example ---\n" + tsExample);
console.log("\n--- Math Example ---\n" + pythagoreanTheorem);

view raw JSON →