Stable heading ids
This commit is contained in:
@@ -3,7 +3,8 @@ import { escape } from 'lodash';
|
||||
import { Node } from 'slate';
|
||||
import slug from 'slug';
|
||||
|
||||
export default function headingToSlug(node: Node) {
|
||||
const level = node.type.replace('heading', 'h');
|
||||
return escape(`${level}-${slug(node.text)}-${node.key}`);
|
||||
export default function headingToSlug(node: Node, index: number = 0) {
|
||||
const slugified = escape(slug(node.text));
|
||||
if (index === 0) return slugified;
|
||||
return `${index}-${slugified}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user