close
Skip to main content

Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score94%
License
MIT
Downloads35/wk
Published2 weeks ago (4.0.0)

🖨️ Render markdown to HTML using the unified ecosystem.

🖨️ Markdown

JSR JSR Score NPM Coverage

📑 Examples

Rendering markdown

import { markdown } from "./mod.ts"

// Render markdown (GitHub Flavored Markdown is enabled by default)
markdown("# Hello, world!")

// Toggle additional features through options
markdown("$\\pi$ is ==irrational==", { math: true, markers: true })

// Raw HTML is escaped by default, opt-in with the `html` option
markdown("<b>trusted</b>", { html: true })

// Retrieve frontmatter metadata
const { value, metadata } = markdown("---\ntitle: foo\n---\nbar", { frontmatter: true, metadata: true })
console.log(value, metadata.frontmatter) // "bar" { title: "foo" }

Reusing a renderer and hooking custom rules

import { Renderer } from "./renderer.ts"

const renderer = new Renderer({
  highlighting: true,
  wikilinks: { resolve: (link) => `/wiki/${link}` },
  // Hook the underlying markdown-it instance for custom rules and renderers
  hooks(engine) {
    engine.renderer.rules.code_inline = (tokens, index) => `<kbd>${engine.utils.escapeHtml(tokens[index].content)}</kbd>`
  },
})
renderer.render("# Hello, world!")

✨ Features

📜 Licenses and credits

Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE

This library relies on the awesome markdown-it library.

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@libs/markdown

Import symbol

import * as markdown from "@libs/markdown";
or

Import directly with a jsr specifier

import * as markdown from "jsr:@libs/markdown";