File tree 2 files changed +16
-23
lines changed
2 files changed +16
-23
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,17 @@ test("markdown-it-toc-and-anchor toc", t => {
31
31
"should work with soft breaks"
32
32
) ;
33
33
34
+ t . is (
35
+ mdIt (
36
+ `**123**+
37
+ @[toc]` ,
38
+ { toc : true }
39
+ ) ,
40
+ `<p><strong>123</strong>+
41
+ </p>\n` ,
42
+ "should work with line breaks after text before toc"
43
+ ) ;
44
+
34
45
t . is (
35
46
mdIt (
36
47
`@[tac]
@@ -86,17 +97,17 @@ and next element in the same inline token`
86
97
# Heading` ,
87
98
{
88
99
toc : true ,
89
- tocClassName : null ,
100
+ tocClassName : null
90
101
}
91
102
) ,
92
103
`<p><ul>
93
104
<li><a href="#heading">Heading</a></li>
94
105
</ul>
95
106
</p>
96
107
<h1 id="heading">Heading</h1>\n` ,
97
- /* eslint-disable max-len */
98
- "should handle not including default class in anchors when setting tocClassName to null"
99
- )
108
+ /* eslint-disable max-len */
109
+ "should handle not including default class in anchors when setting tocClassName to null"
110
+ ) ;
100
111
101
112
t . is (
102
113
mdIt (
Original file line number Diff line number Diff line change @@ -253,19 +253,6 @@ export default function(md, options) {
253
253
let token ;
254
254
let match ;
255
255
256
- while (
257
- state . src . indexOf ( "\n" ) >= 0 &&
258
- state . src . indexOf ( "\n" ) < state . src . indexOf ( TOC )
259
- ) {
260
- if ( state . tokens . slice ( - 1 ) [ 0 ] . type === "softbreak" ) {
261
- state . src = state . src
262
- . split ( "\n" )
263
- . slice ( 1 )
264
- . join ( "\n" ) ;
265
- state . pos = 0 ;
266
- }
267
- }
268
-
269
256
if (
270
257
// Reject if the token does not start with @[
271
258
state . src . charCodeAt ( state . pos ) !== 0x40 ||
@@ -290,12 +277,7 @@ export default function(md, options) {
290
277
token = state . push ( "toc_close" , "toc" , - 1 ) ;
291
278
292
279
// Update pos so the parser can continue
293
- const newline = state . src . indexOf ( "\n" ) ;
294
- if ( newline !== - 1 ) {
295
- state . pos = state . pos + newline ;
296
- } else {
297
- state . pos = state . pos + state . posMax + 1 ;
298
- }
280
+ state . pos = state . pos + 6 ;
299
281
300
282
return true ;
301
283
} ) ;
You can’t perform that action at this time.
0 commit comments