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-normalize-paths

v0.2.1

Published

Remark plugin to normalize relative paths in markdown

Downloads

2

Readme

remark-normalize-paths

Remark plugin to normalize relative paths in markdown, by resolving them to the current markdown file's directory.

Content

What is this?

This package is a remark plugin.

When should I use this?

If you want to resolve paths relative to the current file.

All url parameters of all nodes are resolved, as well as all string-valued attributes of MDX flow elements and directives, that look like a relative path, i.e. that start with ./ or ../.

You can further specifiy, whether you want to normalize a path only, if the normalized target exists, see Options for details.

Install

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

npm install remark-normalize-paths

Use

import remarkDirective from 'remark-directive';
import remarkMdx from 'remark-mdx';
import remarkNormalizePaths from 'remark-normalize-paths';
import remarkParse from 'remark-parse';
import { unified } from 'unified';

const processor = unified()
  .use(remarkParse)
  .use(remarkDirective)
  .use(remarkNormalizePaths, { exclude: ["link", "<CustomComponent>"] });

This markdown in the file /workspace/content/index.md:

![](./picture.jpg)

[Read more](./all/index.html)

<img src="../other-picture.png" />

::Quote[MDX is great]{author="Me" avatar="./me.jpg" .xxl}

<CustomComponent ref="./input.txt" />

would yield the following paths:

  • ./picture.jpg -> /workspace/content/picture.jpg
  • ./all/index.html -> ./all/index.html, because links are excluded in the extensions configuration
  • ../other-picture.png -> /workspace/other-picture.png
  • ./me.jpg -> /workspace/content/me.jpg

Options

rebase?: string

Path to use as new base path and make all resulting paths relative to this path.

Default is undefined, i.e. resulting paths will be absolute.

checkExistence?: boolean

Normalize path only, if normalized path exists, leave untouched otherwise.

Default is true.

include?: string[]

List of MDX element types or JSX tags (if put in angle brackets, e.g. <img>)to include during path normalization (only the named types will be included).

Default is undefined, i.e. all MDX element types will be included.

exclude?: string[]

List of MDX element types or JSX tags (if put in angle brackets, e.g. <img>) to exclude during path normalization. E.g. ['link', '<a>'] to exclude markdown links and JSX anchor tags.

Default is undefined, i.e. no MDX element types will be excluded.