Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/denoland/deno-gfm
Server-side GitHub Flavored Markdown rendering for Deno
https://github.com/denoland/deno-gfm
deno gfm markdown
Last synced: about 1 month ago
JSON representation
Server-side GitHub Flavored Markdown rendering for Deno
- Host: GitHub
- URL: https://github.com/denoland/deno-gfm
- Owner: denoland
- License: mit
- Created: 2021-10-11T20:42:16.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-29T15:13:27.000Z (3 months ago)
- Last Synced: 2024-09-30T07:21:00.061Z (about 1 month ago)
- Topics: deno, gfm, markdown
- Language: TypeScript
- Homepage: https://jsr.io/@deno/gfm
- Size: 385 KB
- Stars: 220
- Watchers: 15
- Forks: 33
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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:
```sh
deno add @deno/gfm
``````js
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 = `
main {
max-width: 800px;
margin: 0 auto;
}
${CSS}
${body}
`;
```### 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:
```html
... markdown body here ...
```If you want to use the light or dark theme depending on the user's browser
preference, set the following:```html
... 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:```js
import { CSS, render } from "@deno/gfm";// Add support for TypeScript, Bash, and Rust.
import "npm:[email protected]/components/prism-typescript.js";
import "npm:[email protected]/components/prism-bash.js";
import "npm:[email protected]/components/prism-rust.js";
```A full list of supported languages is available here:
https://unpkg.com/browse/[email protected]/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:```ts
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:```ts
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 = `
main {
max-width: 800px;
margin: 0 auto;
}
${CSS}
${KATEX_CSS}
${body}
`;
```