rehype plugins that match how GitHub transforms markdown on their site.
π Note: work in progress. some things are not yet finished.
- What is this?
- When should I use this?
- Install
- Packages
- Examples
- Types
- Compatibility
- Security
- Related
- Contribute
- Notice
- License
This project is a monorepo that contains many packages that can be used together or on their own, with defaults to match GitHub or with configuration to match your site, to process user content for safe use on the web.
You can use these tools when you need to:
- match GitHub in how it transforms markdown to HTML
- build similar pipelines to bring user content to the masses
Currently, install and use each package manually.
remark-github-break
β turn normal line endings into hard breaks (comments)remark-github-yaml-metadata
β show frontmatter as a table (files)rehype-github-alert
β enhance alerts (everywhere)rehype-github-color
β enhance code for colors (comments)rehype-github-dir
β adddir=auto
to elements (everywhere)rehype-github-emoji
β enhance emoji and gemoji (everywhere)rehype-github-heading
β enhance headings (files)rehype-github-highlight
β perform syntax highlighting on code (to do, meanwhile userehype-starry-night
)rehype-github-image
β enhance images (everywhere)rehype-github-link
β enhance links (everywhere)rehype-github-mention
β enhance mentions (to do)rehype-github-notranslate
β enhance raw text withnotranslate
(comments)rehype-github-reference
β enhance references (to do)rehype-github-sanitize
β clean dangerous HTML (to do, meanwhile userehype-sanitize
)
GitHub additionally includes client side code to enhance certain code blocks by evaluating their contents. This behavior is performed by:
viewscreen-geojson
β viewscreen component for geojson and topojsonviewscreen-mermaid
β viewscreen component for mermaidviewscreen-stl
β viewscreen component for STL (3D geometry)
See example/viewscreen/
on how to use them together.
To do:
- investigate task lists
- investigate mathjax
- investigate port of treelights
- investigate linking to labels, issues, pulls, files, lines in files
A pipeline that gets close to how GitHub transforms comments:
import rehypeGithubAlert from 'rehype-github-alert'
import rehypeGithubColor from 'rehype-github-color'
import rehypeGithubDir from 'rehype-github-dir'
import rehypeGithubEmoji from 'rehype-github-emoji'
import rehypeGithubImage from 'rehype-github-image'
import rehypeGithubLink from 'rehype-github-link'
import rehypeGithubNoTranslate from 'rehype-github-notranslate'
import rehypeRaw from 'rehype-raw'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import remarkGithubBreak from 'remark-github-break'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
const file = await unified()
.use(remarkParse)
.use(remarkGithubBreak)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeRaw)
.use(rehypeGithubAlert)
.use(rehypeGithubColor)
.use(rehypeGithubDir)
.use(rehypeGithubEmoji)
.use(rehypeGithubImage)
.use(rehypeGithubLink)
.use(rehypeGithubNoTranslate)
.use(rehypeSanitize)
.use(rehypeStringify)
.process('hi!')
console.log(String(file))
Yields:
<p dir="auto">hi!</p>
A pipeline that gets close to how GitHub transforms files:
import rehypeGithubAlert from 'rehype-github-alert'
import rehypeGithubDir from 'rehype-github-dir'
import rehypeGithubEmoji from 'rehype-github-emoji'
import rehypeGithubHeading from 'rehype-github-heading'
import rehypeGithubImage from 'rehype-github-image'
import rehypeGithubLink from 'rehype-github-link'
import rehypeRaw from 'rehype-raw'
import rehypeSanitize from 'rehype-sanitize'
import rehypeStringify from 'rehype-stringify'
import remarkGithubYamlMetadata from 'remark-github-yaml-metadata'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
const file = await unified()
.use(remarkParse)
.use(remarkGithubYamlMetadata)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeRaw)
.use(rehypeGithubAlert)
.use(rehypeGithubDir)
.use(rehypeGithubEmoji)
.use(rehypeGithubHeading)
.use(rehypeGithubImage)
.use(rehypeGithubLink)
.use(rehypeSanitize)
.use(rehypeStringify)
.process('hi!')
console.log(String(file))
Yields:
<p dir="auto">hi!</p>
These packages are fully typed with TypeScript.
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 16+. Our projects sometimes work with older versions, but this is not guaranteed.
Be wary of user input and use rehype-sanitize
.
rehype-sanitize
β sanitize HTMLrehype-starry-night
β apply syntax highlighting to code withstarry-night
See contributing.md
in rehypejs/.github
for
ways to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
This project is not affiliated with GitHub.
MIT Β© Titus Wormer