npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rehype-gist

v1.0.0

Published

A rehype plugin for embedding static GitHub Gists in your HTML and MD/X content.

Downloads

111

Readme

rehype-gist

A rehype plugin for embedding static GitHub Gists in your HTML and MD/X content.

GitHub package.json version Release codecov Conventional Commits GitHub

Demo

gist:darylwright/75332f27a6e9bff70bc0406114570829

The above will render a static GitHub Gist on the rehype-gist homepage. More demos can be found here.

Installation

PNPM:

pnpm add rehype-gist

NPM:

npm install rehype-gist

Yarn:

yarn install rehype-gist

Styling

rehype-gist depends on GitHub's Gist stylesheet. Run the following script to download a copy of this stylesheet to use in your project:

Unix shell

curl -s https://gist.github.com/darylwright/75332f27a6e9bff70bc0406114570829.json | jq .stylesheet | xargs -n 1 curl -s -o gist-embed.css

PowerShell

iwr $(iwr https://gist.github.com/darylwright/75332f27a6e9bff70bc0406114570829.json | ConvertFrom-Json).stylesheet -OutFile gist-embed.css

Alternatively, you can browse any Gist's JSON in your browser and find the URL of the stylesheet.

{
  "description": "This is an example code snippet used for test data",
  "public": true,
  "created_at": "2023-06-01T09:50:34.000-03:00",
  "files": ["gist-test.ts"],
  "owner": "darylwright",
  "div": "...",
  "stylesheet": "https://github.githubassets.com/assets/gist-embed-38d69729aad4.css"
}

The default theme of the downloaded stylesheet is GitHub Light. You can change the default appearance by importing themes from elsewhere. gist-syntax-themes is a good source of attractive themes for your Gists. Ensure all stylesheets are imported globally in your project.

The Gists as styled with the default stylesheet have a white border that doesn't align well with the content. Copy and paste the following CSS in your project's global stylesheet to remove this border for all your embedded Gists.

.gist table,
.gist th,
.gist td {
    border-width: 0 !important;
}
body .gist .gist-file {
    border-width: 0;
}

Configuration

| Name | Type | Default | Description | |------------------------|--------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------| | replaceParentParagraph | boolean | true | Transform the parent <p> of the qualifying <code> element into a Gist. Doesn't transform if the Gist <code> element has siblings. | | omitCodeBlocks | boolean | true | Do not transform <code> element whose parent is a <pre> element. | | classNames | string or string[] | | A list of class names to apply to the root element of the rendered Gist. |

Example

import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import rehypeGist from "rehype-gist";

const output = await unified()
  .use(rehypeParse)
  .use(rehypeGist, {
    replaceParentParagraph: false,
    omitCodeBlocks: false,
    classNames: [`border-2`, `my-4`],
  })
  .use(rehypeStringify)
  .process(`
<!doctype html>
<html lang="en">
  <head>
    <title>Transform inline code to static GitHub Gist</title>
  </head>
  <body>
    <code>gist:darylwright/75332f27a6e9bff70bc0406114570829</code>
  </body>
</html>
  `);

Notes

This plugin should be declared before any others that transform <code> tags, or the Gists will not be rendered.

Highlights and removed lines can only be applied to one file at a time in a Gist. Multi-file Gists can still be displayed without highlights and removed lines.

Issues

Please report any issues with this software here. If you would like to contribute to this project, feel free to fork it and send a pull request. Note that this project is governed by a code of conduct.

Acknowledgements

This project was inspired by gatsby-remark-embed-gist by Patricio Treviño.

License

This project is MIT licensed.