remark-definition
v2.0.3
Published
remark plugin to convert text to link by global config.
Maintainers
Readme
remark-definition
This package is unified (remark) plugin to convert text to link by global config.
Install
npm install remark-definitionUsage
see example.ts
import rehypeStringify from 'rehype-stringify'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import { unified } from 'unified'
import remarkDefinition from 'remark-definition'
const file = await unified()
.use(remarkParse)
.use(remarkDefinition, {
// your config here
'next.js': {
url: 'https://github.com/vercel/next.js',
text: 'Next.js',
},
})
.use(remarkRehype)
.use(rehypeStringify)
.process('[next.js][/issues]') // empty link like '[next.js]()' do not support pathanme
console.log(String(file))
// output:
// <p><a href="https://github.com/vercel/next.js/issues">Next.js</a></p>Skip empty link
remark-definition converts empty links by default, e.g. [next.js](), and sets 'renderLink' to false to skip empty link nodes.
await unified()
.use(remarkParse)
.use(remarkDefinition, {
// your config here
'next.js': {
url: 'https://github.com/vercel/next.js',
text: 'Next.js',
},
{ renderLink: false } // options
})Option
The options type [DefinitionValue, RemarkDefinitionPluginOptions] definitions:
export type DefinitionValue =
| string
| {
label?: string
url: string
}
export interface RemarkDefinitionPluginOptions {
/**
* render Link node
* @default true
*/
renderLink?: boolean
/**
* ingnore case, use lower case for map key
* @default true
*/
caseInsensitive?: boolean
}Markdown example
See the innput file input.md and the output file output.md.
Test
run pnpm test
