@@ -22,19 +22,26 @@ describe('Anchors', () => {
22
22
log . clear ( ) ;
23
23
} ) ;
24
24
25
+ it ( 'should add single anchor with auto naming' , ( ) => {
26
+ expect ( transformYfm ( '## Test\n' + '\n' + 'Content\n' ) ) . toBe (
27
+ '<h2 id="test"><a href="#test" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span></a>Test</h2>\n' +
28
+ '<p>Content</p>\n' ,
29
+ ) ;
30
+ } ) ;
31
+
25
32
it ( 'should add single anchor' , ( ) => {
26
33
expect ( transformYfm ( '## Test {#test1}\n' + '\n' + 'Content\n' ) ) . toBe (
27
- '<h2 id="test1"><a href="#test1" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Test</h2>\n' +
34
+ '<h2 id="test1"><a href="#test1" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a>Test</h2>\n' +
28
35
'<p>Content</p>\n' ,
29
36
) ;
30
37
} ) ;
31
38
32
39
it ( 'should add multiple anchors' , ( ) => {
33
40
expect ( transformYfm ( '## Test {#test1} {#test2} {#test3}\n' + '\n' + 'Content\n' ) ) . toBe (
34
41
'<h2 id="test1">' +
35
- '<a id="test3" href="#test3" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>' +
36
- '<a id="test2" href="#test2" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>' +
37
- '<a href="#test1" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Test</h2>\n' +
42
+ '<a id="test3" href="#test3" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a>' +
43
+ '<a id="test2" href="#test2" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a>' +
44
+ '<a href="#test1" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a>Test</h2>\n' +
38
45
'<p>Content</p>\n' ,
39
46
) ;
40
47
} ) ;
@@ -49,9 +56,9 @@ describe('Anchors', () => {
49
56
'{% include [test](./mocks/include-anchor.md) %}\n' ,
50
57
) ,
51
58
) . toBe (
52
- '<h2 id="test0"><a href="#test0" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Test</h2>\n' +
59
+ '<h2 id="test0"><a href="#test0" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a>Test</h2>\n' +
53
60
'<p>Content before include</p>\n' +
54
- '<h1 id="test1"><a href="#test1" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Title</h1>\n' +
61
+ '<h1 id="test1"><a href="#test1" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Title</span ></a>Title</h1>\n' +
55
62
'<p>Content</p>\n' ,
56
63
) ;
57
64
} ) ;
@@ -66,20 +73,20 @@ describe('Anchors', () => {
66
73
'{% include [test](./mocks/include-multiple-anchors.md) %}\n' ,
67
74
) ,
68
75
) . toBe (
69
- '<h2 id="test0"><a href="#test0" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Test</h2>\n' +
76
+ '<h2 id="test0"><a href="#test0" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a>Test</h2>\n' +
70
77
'<p>Content before include</p>\n' +
71
78
'<h1 id="test1">' +
72
- '<a id="test3" href="#test3" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>' +
73
- '<a id="test2" href="#test2" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>' +
74
- '<a href="#test1" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Title</h1>\n' +
79
+ '<a id="test3" href="#test3" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Title</span ></a>' +
80
+ '<a id="test2" href="#test2" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Title</span ></a>' +
81
+ '<a href="#test1" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Title</span ></a>Title</h1>\n' +
75
82
'<p>Content</p>\n' ,
76
83
) ;
77
84
} ) ;
78
85
79
86
it ( 'should be transliterated correctly' , ( ) => {
80
87
expect ( transformYfm ( '## Максимальный размер дисков \n' + '\n' + 'Content\n' ) ) . toBe (
81
88
'<h2 id="maksimalnyj-razmer-diskov">' +
82
- '<a href="#maksimalnyj-razmer-diskov" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>' +
89
+ '<a href="#maksimalnyj-razmer-diskov" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Максимальный размер дисков</span ></a>' +
83
90
'Максимальный размер дисков' +
84
91
'</h2>\n' +
85
92
'<p>Content</p>\n' ,
@@ -89,7 +96,7 @@ describe('Anchors', () => {
89
96
it ( 'should be removed fences after transliteration' , ( ) => {
90
97
expect ( transformYfm ( '## `Test`\n' + '\n' + 'Content\n' ) ) . toBe (
91
98
'<h2 id="test">' +
92
- '<a href="#test" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a><code>Test</code>' +
99
+ '<a href="#test" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Test</span ></a><code>Test</code>' +
93
100
'</h2>\n' +
94
101
'<p>Content</p>\n' ,
95
102
) ;
@@ -106,7 +113,7 @@ describe('Anchors', () => {
106
113
) ,
107
114
) . toBe (
108
115
'<p>Content before include</p>\n' +
109
- '<h2 id="anchor"><a href="#anchor" class="yfm-anchor" aria-hidden="true" rel="nofollow" ></a>Subtitle</h2>\n' +
116
+ '<h2 id="anchor"><a href="#anchor" class="yfm-anchor" aria-hidden="true"><span class="visually-hidden">Subtitle</span ></a>Subtitle</h2>\n' +
110
117
'<p>Subcontent</p>\n' +
111
118
'<p>After include</p>\n' ,
112
119
) ;
0 commit comments