From cb0efae167721d81d966137baa7f3f5f85a75ae7 Mon Sep 17 00:00:00 2001 From: VadimMakishvili Date: Wed, 5 Jul 2023 15:29:38 +0300 Subject: [PATCH] feat(anchors): Add rel=nofollow for anchor links --- src/transform/plugins/anchors/index.ts | 1 + test/anchors.test.ts | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/transform/plugins/anchors/index.ts b/src/transform/plugins/anchors/index.ts index 0a469979..6b80ab33 100644 --- a/src/transform/plugins/anchors/index.ts +++ b/src/transform/plugins/anchors/index.ts @@ -20,6 +20,7 @@ function createLinkTokens(state: StateCore, id: string, setId = false) { open.attrSet('href', '#' + id); open.attrSet('class', 'yfm-anchor'); open.attrSet('aria-hidden', 'true'); + open.attrSet('rel', 'nofollow'); text.content = ''; return [open, text, close]; diff --git a/test/anchors.test.ts b/test/anchors.test.ts index 936244c1..a4e024ac 100644 --- a/test/anchors.test.ts +++ b/test/anchors.test.ts @@ -24,7 +24,7 @@ describe('Anchors', () => { it('should add single anchor', () => { expect(transformYfm('## Test {#test1}\n' + '\n' + 'Content\n')).toBe( - '

Test

\n' + + '

Test

\n' + '

Content

\n', ); }); @@ -32,9 +32,9 @@ describe('Anchors', () => { it('should add multiple anchors', () => { expect(transformYfm('## Test {#test1} {#test2} {#test3}\n' + '\n' + 'Content\n')).toBe( '

' + - '' + - '' + - 'Test

\n' + + '' + + '' + + 'Test\n' + '

Content

\n', ); }); @@ -49,9 +49,9 @@ describe('Anchors', () => { '{% include [test](./mocks/include-anchor.md) %}\n', ), ).toBe( - '

Test

\n' + + '

Test

\n' + '

Content before include

\n' + - '

Title

\n' + + '

Title

\n' + '

Content

\n', ); }); @@ -66,12 +66,12 @@ describe('Anchors', () => { '{% include [test](./mocks/include-multiple-anchors.md) %}\n', ), ).toBe( - '

Test

\n' + + '

Test

\n' + '

Content before include

\n' + '

' + - '' + - '' + - 'Title

\n' + + '' + + '' + + 'Title\n' + '

Content

\n', ); }); @@ -79,7 +79,7 @@ describe('Anchors', () => { it('should be transliterated correctly', () => { expect(transformYfm('## Максимальный размер дисков \n' + '\n' + 'Content\n')).toBe( '

' + - '' + + '' + 'Максимальный размер дисков' + '

\n' + '

Content

\n', @@ -89,7 +89,7 @@ describe('Anchors', () => { it('should be removed fences after transliteration', () => { expect(transformYfm('## `Test`\n' + '\n' + 'Content\n')).toBe( '

' + - 'Test' + + 'Test' + '

\n' + '

Content

\n', ); @@ -106,7 +106,7 @@ describe('Anchors', () => { ), ).toBe( '

Content before include

\n' + - '

Subtitle

\n' + + '

Subtitle

\n' + '

Subcontent

\n' + '

After include

\n', );