diff --git a/index.js b/index.js index 6a850c0..a9bb6bc 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ function anchor (md, opts) { let slug = token.attrGet('id') if (slug == null) { - slug = uniqueSlug(opts.slugify(title), slugs, false, opts.uniqueSlugStartIndex) + slug = uniqueSlug(opts.slugify(title, state.env), slugs, false, opts.uniqueSlugStartIndex) } else { slug = uniqueSlug(slug, slugs, true, opts.uniqueSlugStartIndex) } diff --git a/test.js b/test.js index f7c8169..b764e4a 100644 --- a/test.js +++ b/test.js @@ -232,6 +232,13 @@ test('getTokensText', t => { ) }) +test('slugify', t => { + t.is( + md().use(anchor, { slugify: (title, env) => `${env.docId}-${title}` }).render('# bar', { docId: 'foo' }), + '

bar

\n' + ) +}) + nest('permalink.linkInsideHeader', test => { test('default', t => { t.is( diff --git a/types/index.d.ts b/types/index.d.ts index 7c94aae..d3faa03 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -47,7 +47,7 @@ declare namespace anchor { export interface AnchorOptions { level?: number | number[]; - slugify?(str: string): string; + slugify?(str: string, env: any): string; getTokensText?(tokens: Token[]): string; uniqueSlugStartIndex?: number;