MCPcopy Index your code
hub / github.com/denoland/deno-gfm

github.com/denoland/deno-gfm @1.10.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.10.0 ↗ · + Follow
32 symbols 70 edges 8 files 1 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

deno-gfm

Server-side GitHub Flavored Markdown rendering for Deno, including GitHub style CSS, syntax highlighting, and HTML sanitization.

Usage

First install the package with the command:

deno add @deno/gfm
import { CSS, render } from "@deno/gfm";

const markdown = `
# Hello, world!

| Type | Value |
| ---- | ----- |
| x    | 42    |

\`\`\`js
console.log("Hello, world!");
\`\`\`
`;

const body = render(markdown, {
  baseUrl: "https://example.com",
});

const html = `
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
      main {
        max-width: 800px;
        margin: 0 auto;
      }
      ${CSS}
    </style>
  </head>
  <body>
    <main data-color-mode="light" data-light-theme="light" data-dark-theme="dark" class="markdown-body">
      ${body}
    </main>
  </body>
</html>
`;

Styling

The GitHub CSS styles (https://primer.style) are used. There are two themes available: light and dark.

There are three data attributes that can be used to control the theme:

  • data-color-mode: light or dark or auto.
  • data-light-theme: the name of the light theme (light or dark).
  • data-dark-theme: the name of the dark theme (light or dark).

For example, if you want to use the dark theme only, set the following:




  ... markdown body here ...



If you want to use the light or dark theme depending on the user's browser preference, set the following:




  ... markdown body here ...



Also see the example application in the example/ directory.

Extensibility

By default syntax highlighting for JavaScript, Markdown, and HTML is included. You can include more languages importing them:

import { CSS, render } from "@deno/gfm";

// Add support for TypeScript, Bash, and Rust.
import "npm:prismjs@1.29.0/components/prism-typescript.js";
import "npm:prismjs@1.29.0/components/prism-bash.js";
import "npm:prismjs@1.29.0/components/prism-rust.js";

A full list of supported languages is available here: https://unpkg.com/browse/prismjs@1.29.0/components/

Inline rendering

By default, all rendering is in blocks. There are cases where one would like to render some inline markdown, and this is achievable using the inline setting:

import { render } from "@deno/gfm";

const markdown = "My [Deno](https://deno.land) Blog";
const header = render(markdown, { inline: true });
console.log(header);

Math rendering

By default math rendering is disabled. To enable it, you must include the additional CSS and enable the allowMath setting:

import { CSS, KATEX_CSS, render } from "jsr:@deno/gfm";

const markdown = `
Block math:

$$ y = x^2 $$

Inline math: $y = x^2$
`;

const body = render(markdown, {
  allowMath: true,
});

const html = `
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
      main {
        max-width: 800px;
        margin: 0 auto;
      }
      ${CSS}
      ${KATEX_CSS}
    </style>
  </head>
  <body>
    <main data-color-mode="light" data-light-theme="light" data-dark-theme="dark" class="markdown-body">
      ${body}
    </main>
  </body>
</html>
`;

Extension points exported contracts — how you extend this code

RenderOptions (Interface)
(no doc)
mod.ts
MarkdownSections (Interface)
(no doc)
mod.ts

Core symbols most depended-on inside this repo

render
called by 47
mod.ts
strip
called by 9
mod.ts
getCellText
called by 4
test/server_test.ts
browserTest
called by 3
test/test_utils.ts
getOpts
called by 2
mod.ts
stripSplitBySections
called by 2
mod.ts
startServer
called by 2
test/test_utils.ts
getComputedStyle
called by 2
test/server_test.ts

Shape

Function 16
Method 8
Class 6
Interface 2

Languages

TypeScript100%

Modules by API surface

mod.ts20 symbols
test/test_utils.ts5 symbols
test/test.ts4 symbols
test/server_test.ts2 symbols
example/main.ts1 symbols

For agents

$ claude mcp add deno-gfm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page