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-autofix

v0.6.1

Published

A remark plugin to apply fixes from warnings raised by other plugins

Downloads

15

Readme

remark-autofix

Tests Package

This project, remark-autofix, is a remark plugin to apply fixes from warnings raised by retext plugins. The fixes are applied to the markdown abstract syntax tree when running remark-retext in bridge mode.

Supported Plugins

By default, this plugin only fixes vfile messages emitted from the following retext plugins:

By passing the options parameter, following the API, this plugin is tested to support:

Installation

npm install remark-autofix
# or
yarn add remark-autofix

Usage Examples

NOTE Chained calls to a remark processor's use method must occur in the following order with the following arguments:

  1. use(remark2retext, retextProcessor)
    • The retextProcessor must define a retext processor, which should emit vfile messages.
  2. use(autofix[, options])
    • for the options parameter, see the API.

Remove repeated words in Markdown

With retext-repeated-words:

const remark = require('remark');
const unified = require('unified');
const english = require('retext-english');
const remark2retext = require('remark-retext');
const repeated = require('retext-repeated-words');
const autofix = require('remark-autofix');

const inputMarkdown = `## Example
This link [link](https://example.com/) is not not duplicated.
`
const processor = remark().use(
  remark2retext, unified().use(english).use(repeated)
).use(autofix);

const outputMarkdown = processor.processSync(inputMarkdown).toString();

The outputMarkdown should be:

## Example

This [link](https://example.com/) is not duplicated.

Censor profanities in Markdown

With retext-profanities:

const remark = require('remark');
const unified = require('unified');
const english = require('retext-english');
const remark2retext = require('remark-retext');
const profanities = require('retext-profanities');
const autofix = require('remark-autofix');

const inputMarkdown = `Ah geez, you are not a loser.
`
const processor = remark().use(
  remark2retext, unified().use(english).use(profanities)
).use(autofix, {
  fixers: {
    'retext-profanities': (message) => {
    // Censor all but first letter of certain cuss words
    if (message.profanitySeverity >= 2 ) {
      return message.actual.replace(/\B./g,'-')
    }
  }
});

const outputMarkdown = processor.processSync(inputMarkdown).toString();

The outputMarkdown should be:

Ah g---, you are not a l----.

API

remark().use(remark2retext, retextProcessor).use(autofix, options)

remark and remark2retext

These must be imported from remark and remark-retext.

retextProcessor

A retext processor created by chaining unified's use method on:

  • a parser such as retext-english
  • one or more supported retext plugins to emit vfile messages
autofix

This is imported from this package, remark-autofix. It applies fixes to markdown from all supported vfile messages emitted from retextProcessor.

options

This is an optional object with one fixers property containing an object defined below.

options.fixers

This is an object to map retext plugin names to custom functions. See supported plugin names.

Each function provided in fixers should have the following signature:

Parameters:

For supported plugins, each message has the following relevant custom properties in addition to the vfile-message standard:

  • actual string identifying the part of the vfile that should be altered or removed.
  • expected array of strings. For certain plugins, the array may be empty to indicate that the actual value should be removed.

Return:

  • (string or null)

The plugin takes no action if the function returns null. A returned string becomes the sole value to consider from the message. The plugin evaluates all returned values from partially overlapping location ranges for the value of a single replacement. The plugin replaces all mdast nodes in the range with a single mdast node taking on the following value:

  • If possible, the first (by location.start) of the unique values returned for all overlapping messages
  • Else, a value with the maximum longest common substring with the full range of overlapping messages

Ecosystem

This repository works in conjunction with

  • the remark processor
  • the remark-retext processor
  • A retext processor created by chaining unified's use method on:

The plugin works with mdast to represent markdown and nlcst to represent text.

License

MIT licensed