GithubHelp home page GithubHelp logo

ry / deno-gfm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from denoland/deno-gfm

2.0 1.0 0.0 237 KB

Server-side GitHub Flavored Markdown rendering for Deno

Home Page: https://deno.land/x/gfm

License: MIT License

TypeScript 79.41% Makefile 3.19% SCSS 17.40%

deno-gfm's Introduction

deno-gfm

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

Usage

import { CSS, render } from "https://deno.land/x/gfm/mod.ts";

const markdown = `
# Hello, world!

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

\`\`\`js
console.log("Hello, world!");
\`\`\`
`;
const rootUrl = "https://example.com";

const body = render(markdown, rootUrl);

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:

<div data-color-mode="dark" data-dark-theme="dark" class="markdown-body">
  ... markdown body here ...
</div>

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

<div data-color-mode="auto" data-light-theme="light" data-dark-theme="dark" class="markdown-body">
  ... markdown body here ...
</div>

Also see the example application in the example/ directory.

Extensability

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

import { CSS, render } from "https://deno.land/x/gfm/mod.ts";

// Add support for TypeScript, Bash, and Rust.
import "https://esm.sh/[email protected]/components/prism-typescript?no-check";
import "https://esm.sh/[email protected]/components/prism-bash?no-check";
import "https://esm.sh/[email protected]/components/prism-rust?no-check";

A full list of supported languages is available here: https://unpkg.com/browse/[email protected]/components/

deno-gfm's People

Contributors

crowlkats avatar kidonng avatar lucacasonato avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.