0.3.0 • Published 1 year ago

rspress-plugin-directives v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

rspress-plugin-directives NPM Version

简体中文

Rspress plugin to support custom directive transformations.

Although rspress already supports directive syntax, it is limited to support for its built-in components such as :::warning, :::tip, etc. Beyond these built-in directives, you can't add your own directive-to-component conversion logic.

This plugin allows you to add new custom directives, and conversions from custom directives to global components.

Instead of importing components and using them directly inside an MDX file, with this plugin you can quickly refer to them via directives without importing them.

Usage

npm i rspress-plugin-directives
pnpm add rspress-plugin-directives
import * as path from 'path';
import { defineConfig } from 'rspress/config';
import directives from 'rspress-plugin-directives';

export default defineConfig({
  root: path.join(__dirname, 'docs'),
  plugins: [
    directives({
      directive: 'guide',
      transformer: {
        type: 'globalComponent',
        getComponentName: (meta) => 'Guide',
        componentPath: path.join(__dirname, './components/Guide.tsx'),
      },
    }),
  ],
});

The configuration above will register a new directive :::guide that will be transformed into a global component Guide from the file ./components/Guide.tsx.

Write markdown like this:

:::guide
Skip this section if you are already familiar with the topic.
:::

And it will be transformed into:

<Guide>Skip this section if you are already familiar with the topic.</Guide>
0.3.0

1 year ago

0.2.0

1 year ago

0.1.2-beta.0

1 year ago

0.1.1

1 year ago

0.1.3

1 year ago

0.1.4-beta.0

1 year ago

0.1.3-beta.0

1 year ago

0.1.0

1 year ago