rehype-autolink-headings Simple Version
关于我看不下去 rehype-autolink-headings 过于复杂这件事
views
| comments
本来 rehype-autolink-headings
是一个 @unified
系列的 rehype
插件,用于给标题添加链接锚点。但是咱也不知道为啥,就这么一个简单的添加链接的插件,却塞了一堆乱七八糟的东西和依赖,所以就…重写了。
其他用法应该都是兼容旧库的。就这样吧。
Links#
cworld1 / rehype-autolink-headings-simple
Waiting for api.github.com...
???
???
???
Detail#
A simple version of rehype-autolink-headings ↗.
Less dependencies and less useless code. Using typescript to develop.
Usage#
npm install rehype-autolink-headings-simple
bashimport { rehypeAutolinkHeadings } from 'rehype-autolink-headings-simple'
import { parse } from 'rehype-parse'
import { stringify } from 'rehype-stringify'
import { unified } from 'unified'
const processor = unified()
.use(parse)
.use(rehypeAutolinkHeadings, {
behavior: 'append',
properties: {
behavior: 'append',
properties: { className: ['anchor'] },
content: { type: 'text', value: '#' }
}
})
.use(stringify)
const result = processor.processSync('<h1>Heading</h1>').toString()
jsKnown issues#
Astro should change render order manually. See Astro: Heading IDs and plugins ↗
License#
The MIT License (MIT).