5
5
6
6
import { containerFlow } from '../util/container-flow.js'
7
7
import { checkBullet } from '../util/check-bullet.js'
8
- import { checkOtherBullet } from '../util/check-other- bullet.js'
8
+ import { checkBulletOther } from '../util/check-bullet-other .js'
9
9
import { checkRule } from '../util/check-rule.js'
10
10
11
11
/**
12
12
* @type {Handle }
13
13
* @param {List } node
14
14
*/
15
- export function list ( node , _ , context ) {
15
+ export function list ( node , parent , context ) {
16
16
const exit = context . enter ( 'list' )
17
- const currentBullet = context . currentBullet
17
+ const bulletCurrent = context . bulletCurrent
18
18
/** @type {string } */
19
19
let bullet = checkBullet ( context )
20
- const otherBullet = checkOtherBullet ( context )
20
+ /** @type {string } */
21
+ const bulletOther = checkBulletOther ( context )
22
+ const bulletLastUsed = context . bulletLastUsed
21
23
22
24
if ( node . ordered ) {
23
25
bullet = '.'
24
26
} else {
25
27
const firstListItem = node . children ? node . children [ 0 ] : undefined
26
28
let useDifferentMarker = false
27
29
28
- // If there’s an empty first list item, directly in two list items,
30
+ if (
31
+ parent &&
32
+ context . options . bulletOther &&
33
+ bulletLastUsed &&
34
+ bullet === bulletLastUsed
35
+ ) {
36
+ useDifferentMarker = true
37
+ }
38
+
39
+ // If there’s an empty first list item directly in two list items,
29
40
// we have to use a different bullet:
30
41
//
31
42
// ```markdown
@@ -34,16 +45,22 @@ export function list(node, _, context) {
34
45
//
35
46
// …because otherwise it would become one big thematic break.
36
47
if (
48
+ // Bullet could be used as a thematic break marker:
49
+ ( bullet === '*' || bullet === '-' ) &&
50
+ // Empty first list item:
37
51
firstListItem &&
38
- // Empty list item:
39
52
( ! firstListItem . children || ! firstListItem . children [ 0 ] ) &&
40
53
// Directly in two other list items:
54
+ context . stack [ context . stack . length - 1 ] === 'list' &&
41
55
context . stack [ context . stack . length - 2 ] === 'listItem' &&
42
- context . stack [ context . stack . length - 4 ] === 'listItem'
56
+ context . stack [ context . stack . length - 3 ] === 'list' &&
57
+ context . stack [ context . stack . length - 4 ] === 'listItem' &&
58
+ // That are each the first child.
59
+ context . indexStack [ context . indexStack . length - 1 ] === 0 &&
60
+ context . indexStack [ context . indexStack . length - 2 ] === 0 &&
61
+ context . indexStack [ context . indexStack . length - 3 ] === 0 &&
62
+ context . indexStack [ context . indexStack . length - 4 ] === 0
43
63
) {
44
- // Note: this is only needed for first children of first children,
45
- // but the code checks for *children*, not *first*.
46
- // So this might generate different bullets where not really needed.
47
64
useDifferentMarker = true
48
65
}
49
66
@@ -60,6 +77,7 @@ export function list(node, _, context) {
60
77
61
78
while ( ++ index < node . children . length ) {
62
79
const item = node . children [ index ]
80
+
63
81
if (
64
82
item &&
65
83
item . type === 'listItem' &&
@@ -74,13 +92,14 @@ export function list(node, _, context) {
74
92
}
75
93
76
94
if ( useDifferentMarker ) {
77
- bullet = otherBullet
95
+ bullet = bulletOther
78
96
}
79
97
}
80
98
81
- context . currentBullet = bullet
99
+ context . bulletCurrent = bullet
82
100
const value = containerFlow ( node , context )
83
- context . currentBullet = currentBullet
101
+ context . bulletLastUsed = bullet
102
+ context . bulletCurrent = bulletCurrent
84
103
exit ( )
85
104
return value
86
105
}
0 commit comments