Skip to content

Commit 409dacb

Browse files
committed
Fix to capture parent of ignore comment
1 parent 81c48ec commit 409dacb

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,8 @@ export function excerpt(tree, options = {}) {
7878
const children = []
7979
let index = -1
8080

81-
while (++index < node.children.length) {
81+
while (++index < node.children.length && !found) {
8282
const result = preorder(node.children[index])
83-
84-
if (found) {
85-
break
86-
}
87-
8883
// @ts-expect-error: assume content model matches.
8984
if (result) children.push(result)
9085
}

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ test('hastUtilExcerpt', (t) => {
2222
'should copy to an excerpt comment'
2323
)
2424

25+
t.deepEqual(
26+
excerpt(
27+
h('div', [
28+
h('p', ['Lorem ipsum dolor sit amet.', u('comment', 'more'), 'Consectetur adipisicing elit.'])
29+
])
30+
),
31+
h('div', [h('p', 'Lorem ipsum dolor sit amet.')]),
32+
'should copy to an excerpt comment inside a paragraph'
33+
)
34+
2535
t.deepEqual(
2636
excerpt(
2737
h('div', [

0 commit comments

Comments
 (0)