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

@roofox/remark-gatsby-plugins-wrapper

v0.1.0

Published

A Remark plugin to support gatsby-remark-* plugins

Downloads

13

Readme

@roofox/remark-gatsby-plugins-wrapper

A Remark plugin to add support for (some) gatsby-remark-* plugins.

With @roofox/remark-gatsby-plugins-wrapper you can use some gatsby-remark-* plugins with Remark.

There are just a couple of gatsby-remark-* plugins that works fine with @roofox/remark-gatsby-plugins-wrapper, since most plugins depends explicitly on some gatsby related properties like actions, store, getNodes, schema, etc. this kind of plugins are not supported within this Remark plugin.

Installation

You need to install @roofox/remark-gatsby-plugins-wrapper using NPM or Yarn When using Remark.

npm install -D @roofox/remark-gatsby-plugins-wrapper
yarn add --dev @roofox/remark-gatsby-plugins-wrapper

How to use it

Just add @roofox/remark-gatsby-plugins-wrapper with the use function as any other Remark plugin.

const remarkGatsbyPluginsWrapper = require("@roofox/remark-gatsby-plugins-wrapper");
const processor = remark();

processor.use(remarkGatsbyPluginsWrapper);

Adding gatsby-remark-* plugins

Gatsby's documentation about using plugins is pretty straighforward and @roofox/remark-gatsby-plugins-wrapper use the exact same plugin array format:

remark()
  .use(require('@roofox/remark-gatsby-plugins-wrapper'), {
    plugins: [
      {
        resolve: "gatsby-remark-smartypants",
        options: {
          dashes: "oldschool"
        }
      },
      {
        resolve: "gatsby-remark-prismjs",
        options: {
          showLineNumbers: true,
        },
      },
    ]
  });

Supported gatsby-remark-* plugins

Example

  1. Create an empty project using mkdir my-test && npm init -y.

  2. Install the followings dependencies: npm install remark remark-rehype rehype-raw rehype-format rehype-stringify remark-emoji @roofox/remark-gatsby-plugins-wrapper gatsby-remark-smartypants gatsby-remark-prismjs prismjs.

  3. Create a test.js file with the following content:

const remark = require("remark");
const remark2rehype = require("remark-rehype");
const raw = require("rehype-raw");
const html2format = require("rehype-format");
const stringify = require("rehype-stringify");
const gatsbyPluginsWrapper = require("@roofox/remark-gatsby-plugins-wrapper");

const processor = remark()
  // A native remark plugin
  .use(require("remark-emoji"))
  // This plugin
  .use(gatsbyPluginsWrapper, {
    // gatsby-remark-* plugins
    plugins: [
      {
        resolve: "gatsby-remark-smartypants",
        options: {
          dashes: "oldschool",
        },
      },
      {
        resolve: "gatsby-remark-prismjs",
        options: {
          showLineNumbers: true,
        },
      },
    ],
  })
  .use(remark2rehype, { allowDangerousHtml: true })
  .use(raw)
  .use(html2format)
  .use(stringify);

const md = `# Title

Lorem ipsum

This is an \`inline code\`.

> "Great quote -- with some style ---"

# :dog: :+1: :-)

\`\`\`javascript
console.log("Hello world");
\`\`\`

**BYE**
`;

processor.process(md, (err, file) => {
  if (err) {
    console.error(err);
    return;
  }

  console.log(String(file));
});
  1. Run node test.js and you will get the following output:
<h1>Title</h1>
<p>Lorem ipsum</p>
<p>This is an <code class="language-text">inline code</code>.</p>
<blockquote>
  <p>“Great quote – with some style —”</p>
</blockquote>
<h1>🐶 👍 :-)</h1>
<div class="gatsby-highlight" data-language="javascript">
  <pre style="counter-reset: linenumber NaN" class="language-javascript line-numbers"><code class="language-javascript">console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"Hello world"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code><span aria-hidden="true" class="line-numbers-rows" style="white-space: normal; width: auto; left: 0;"><span></span></span></pre>
</div>
<p><strong>BYE</strong></p>