@@ -18,30 +18,8 @@ export function all(h, parent) {
18
18
/** @type {Array<MdastNode> } */
19
19
const values = [ ]
20
20
let index = - 1
21
- let length = nodes . length
22
- let child = nodes [ index + 1 ]
23
-
24
- // Trim initial and final `<br>`s.
25
- // They’re not semantic per HTML, and they can’t be made in markdown things
26
- // like paragraphs or headings.
27
- while ( child && child . type === 'element' && child . tagName === 'br' ) {
28
- index ++
29
- child = nodes [ index + 1 ]
30
- }
31
-
32
- child = nodes [ length - 1 ]
33
21
34
- while (
35
- length - 1 > index &&
36
- child &&
37
- child . type === 'element' &&
38
- child . tagName === 'br'
39
- ) {
40
- length --
41
- child = nodes [ length - 1 ]
42
- }
43
-
44
- while ( ++ index < length ) {
22
+ while ( ++ index < nodes . length ) {
45
23
// @ts -expect-error assume `parent` is a parent.
46
24
const result = one ( h , nodes [ index ] , parent )
47
25
@@ -52,5 +30,18 @@ export function all(h, parent) {
52
30
}
53
31
}
54
32
55
- return values
33
+ let start = 0
34
+ let end = values . length
35
+
36
+ while ( start < end && values [ start ] . type === 'break' ) {
37
+ start ++
38
+ }
39
+
40
+ while ( end > start && values [ end - 1 ] . type === 'break' ) {
41
+ end --
42
+ }
43
+
44
+ return start === 0 && end === values . length
45
+ ? values
46
+ : values . slice ( start , end )
56
47
}
0 commit comments