File tree Expand file tree Collapse file tree 3 files changed +54
-7
lines changed Expand file tree Collapse file tree 3 files changed +54
-7
lines changed Original file line number Diff line number Diff line change @@ -18,17 +18,39 @@ export function all(h, parent) {
1818 // @ts -expect-error Assume `parent` is a parent.
1919 const nodes = parent . children || [ ]
2020 /** @type {Array.<MdastNode> } */
21- let values = [ ]
21+ const values = [ ]
2222 let index = - 1
23- /** @type { MdastNode|Array.<MdastNode> } */
24- let result
23+ let length = nodes . length
24+ let child = nodes [ index + 1 ]
2525
26- while ( ++ index < nodes . length ) {
26+ // Trim initial and final `<br>`s.
27+ // They’re not semantic per HTML, and they can’t be made in markdown things
28+ // like paragraphs or headings.
29+ while ( child && child . type === 'element' && child . tagName === 'br' ) {
30+ index ++
31+ child = nodes [ index + 1 ]
32+ }
33+
34+ child = nodes [ length - 1 ]
35+
36+ while (
37+ length - 1 > index &&
38+ child &&
39+ child . type === 'element' &&
40+ child . tagName === 'br'
41+ ) {
42+ length --
43+ child = nodes [ length - 1 ]
44+ }
45+
46+ while ( ++ index < length ) {
2747 // @ts -expect-error assume `parent` is a parent.
28- result = one ( h , nodes [ index ] , parent )
48+ const result = one ( h , nodes [ index ] , parent )
2949
30- if ( result ) {
31- values = values . concat ( result )
50+ if ( Array . isArray ( result ) ) {
51+ values . push ( ...result )
52+ } else if ( result ) {
53+ values . push ( result )
3254 }
3355 }
3456
Original file line number Diff line number Diff line change 11< p > alpha< br > bravo</ p >
22< pre > charlie< br > delta</ pre >
3+ < p > < br > </ p >
4+ < p > echo< br > </ p >
5+ < p > foxtrot< br > < br > </ p >
6+ < p > < br > golf</ p >
7+ < p > < br > < br > hotel</ p >
8+ < p > < br > india< br > </ p >
9+ < p > < br > < br > juliett< br > < br > </ p >
10+ < h1 > < br > kilo</ h1 >
11+ < h1 > lima< br > </ h1 >
Original file line number Diff line number Diff line change 33
44 charlie
55 delta
6+
7+ echo
8+
9+ foxtrot
10+
11+ golf
12+
13+ hotel
14+
15+ india
16+
17+ juliett
18+
19+ # kilo
20+
21+ # lima
You can’t perform that action at this time.
0 commit comments