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

remark-inline-svg

v1.1.1

Published

Remark plugin that inlines SVG images from markdown and optimises them with SVGO

Downloads

387

Readme

remark-inline-svg

Downloads Size version MIT License

Plugin that takes SVG images in markdown, optimises them with SVGO and adds them inline to the HTML output.

Installation

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:

npm install remark-inline-svg

In Deno with esm.sh:

import inlineSVG from 'https://esm.sh/remark-inline-svg@1';

In browsers with esm.sh:

<script type="module">
  import inlineSVG from 'https://esm.sh/remark-inline-svg@1?bundle';
</script>

Usage

Say we have the following file example.md:

# Hello

This is a test markdown document.

![Inline SVG](circle.inline.svg)

Cheers

And our module example.js looks as follows:

import { remark } from 'remark';
import inlineSVG from 'remark-inline-svg';
import { readSync } from 'to-vfile';

const file = readSync('./example.md');

remark()
  .use(inlineSVG)
  .process(file, function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Now running node example.js yields:

# Hello

This is a test markdown document.

<figure class="markdown-inline-svg">
  <svg fill="none" viewBox="0 0 250 250" role="img" aria-hidden="true"><circle cx="125" cy="125" r="100" fill="#BA5B5B"/></svg>
</figure>

Cheers

Options

| Key | Default value | Description | | ------------------------- | --------------------- | ---------------------------------------------------------- | | suffix | ".inline.svg" | The plugin only processes SVG files ending with this value | | replace | undefined | Lets you replace strings within the SVG file | | className | markdown-inline-svg | class of the wrapper element |

suffix

This plugin will ignore SVG files if they don't have the specified suffix, set to .inline.svg by default. This is to minimise disruption to your workflow.

replace

Array of strings to replace with other strings, for example:

{
  replace: {
    "#41DE50": "currentColor"
  }
}

Then #41DE50 will be replaced with currentColor in the SVG output.

className

The inlined SVG is wrapped in a <figure> element, and given a class of markdown-inline-svg to let you apply some custom styles. You can change that class by modifiying the value of the className option.

<!-- You can change this class name 👇 -->
<figure class="markdown-inline-svg">
  <svg fill="none" viewBox="0 0 250 250" role="img" aria-hidden="true">
    <circle cx="125" cy="125" r="100" fill="#BA5B5B" />
  </svg>
</figure>

SVGO configuration

The SVGO configuration is as follows:

const svgoPlugins = [
  {
    name: 'preset-default',
    params: {
      overrides: {
        // disable plugins
        removeTitle: false,
        removeDesc: false,
      },
    },
  },
  'removeXMLNS',
  'removeDimensions',
  'sortAttrs',
];

TODO:

  • [ ] Support titles