remark-plugin-find-and-replace
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Purpose

To find and replace strings in a Remark based project. I created this with the intention of using it with Astro.

Installation

npm install -D remark-plugin-find-and-replace

Usage

In an Astro project, here's how you would use the plugin:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import { RemarkPluginFindAndReplace } from 'remark-plugin-find-and-replace';

// https://astro.build/config
export default defineConfig({
  // ...
  markdown: {
    remarkPlugins: [
      RemarkPluginFindAndReplace({
        replacements: [
          // Replaces all strings that look like "%VERSION%" with "2.6.2"
          { pattern: '%VERSION%', replacement: "2.6.2" },
          // Replacement can be anything you pass as a "replacement" as noted here:
          // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#replacement
          { pattern: 'find a match', replacement: (match) => return `match: ${match}` },
          // You can also pass in regex, just make sure to provide the "g" flag for global regex.
          { pattern: /LICENSE/g, replacement: "[MIT LICENSE](https://opensource.org/license/mit/)" }
        ]
      })
    ]
  },
  // ...
})

Readme

Keywords

Package Sidebar

Install

npm i remark-plugin-find-and-replace

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

8.9 kB

Total Files

5

Last publish

Collaborators

  • konnor_rogers