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 🙏

© 2026 – Pkg Stats / Ryan Hefner

remark-inline-svg-flex

v1.0.0

Published

Customizable Remark plugin to inline and optimize SVGs with SVGO, with robust path resolution.

Readme

remark-inline-svg-flex

Downloads version MIT License

Flexible Remark plugin that inlines and optimizes SVGs with SVGO, featuring customizable path resolution, HTML wrappers and more.

Features

✔️ Robust and customizable path resolution

  • If the SVG path is absolute, it will use the project directory as root.
  • If the path is relative and assetsDir is defined, it is resolved relative to the assetsDir directory.
  • Otherwise, the path is resolved relative to the Markdown file’s location.

✔️ Custom HTML wrapper support

Use your own custom HTML wrapper, no wrapper at all, or the default:

<figure class="inline-svg"></figure>

✔️ Optional SVG optimization

SVG optimization can be disabled if needed e.g. if SVGO removes required attributes.

✔️ Configurable suffix

By default, only files ending in .svg are processed. You can customize the suffix to suit your needs.

Installation

npm i remark-inline-svg-flex

Usage

Say we have the following file example.md:

# Some Title

This is a test markdown document.

![some svg](./alien.svg)

And our module example.js looks as the one below:

import { remark } from 'remark';
import remarkParse from 'remark-parse';
import { remarkInlineSvg } from 'remark-inline-svg-flex';
import { readFile } from 'node:fs/promises';

const filePath = './tests/fixtures/example.md';
const markdownString = await readFile(filePath, { encoding: 'utf8' });

/**
 * `filePath` is used as the virtual file path so that relative links
 * inside the markdown file can be resolved correctly by the plugin.
 */
async function myProcess(markdown, filePath) {
  return await remark()
    .use(remarkParse)
    .use(remarkInlineSvg)
    .process({ value: markdown, path: filePath });
}

const result = await myProcess(markdownString, filePath);

console.log(String(result.value));

Now running node example.js yields:

# Some Title

This is a test markdown document.

<figure class="inline-svg">
  <svg width="800" height="800" fill="none" viewBox="0 0 16 16"><path fill="#000" fill-rule="evenodd" d="m8 16-4.458-3.662A6.96 6.96 0 0 1 1 6.96C1 3.116 4.156 0 8 0s7 3.116 7 6.96a6.96 6.96 0 0 1-2.542 5.378zM3 6h2a2 2 0 0 1 2 2v1L3 7.5zm8 0a2 2 0 0 0-2 2v1l4-1.5V6z" clip-rule="evenodd"/></svg>
</figure>

Options

| Key | type | Default value | Description | | ------------------------- | --------------------- | ---------------------------------------- | ---------------------------------------------------------- | | suffix | string | '.svg' | The plugin only processes SVG files ending with this value | | assetsDir | string \| undefined | undefined | Base directory where SVG files are located | | wrapper | string | '<figure class="inline-svg"></figure>' | HTML wrapper used to wrap the inlined SVG | | svgo | boolean | true | Enable or disable SVG optimization |

suffix

Only image nodes whose URL ends with the specified suffix will be processed. Defaults to '.svg'.

assetsDir

Base directory where SVG files are located. By default is undefined and it will resolve paths either in an absolute or relative manner.

wrapper

Defines the HTML wrapper used around the inlined SVG.

  • Set to an empty string '' to disable wrapping entirely.
  • Defaults to:
<figure class="inline-svg"></figure>

svgo

The SVG's are optimized by default. Disable it by setting it to false.

Path supported

Remote URLs http://, https:// and other external URLs are ignored.

Examples of supported paths:

example.svg
/example.svg
/tests/assets/example.svg
./example.svg
../assets/example.svg

SVGO configuration

SVGO is configured to use the default preset of plugins and the removeXMLNS plugin.

{ plugins: ['preset-default', 'removeXMLNS'] }