Skip to content

Commit a4b88f0

Browse files
committed
Fix bug when straddling void nodes
1 parent da1d73f commit a4b88f0

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

lib/handlers/li.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import {convertElement} from 'hast-util-is-element'
9-
import {shallow} from '../util/shallow.js'
109
import {wrapChildren} from '../util/wrap-children.js'
1110

1211
const p = convertElement('p')
@@ -36,14 +35,13 @@ export function li(h, node) {
3635
checkbox.properties.type === 'radio')
3736
) {
3837
checked = Boolean(checkbox.properties.checked)
39-
clone = Object.assign(shallow(node), {
38+
clone = {
39+
...node,
4040
children: [
41-
Object.assign(shallow(head), {
42-
children: head.children.slice(1)
43-
}),
41+
{...head, children: head.children.slice(1)},
4442
...node.children.slice(1)
4543
]
46-
})
44+
}
4745
}
4846
}
4947

lib/util/shallow.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/util/wrap.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import extend from 'extend'
88
import {phrasing} from 'mdast-util-phrasing'
9-
import {shallow} from './shallow.js'
109

1110
/**
1211
* @param {Array.<MdastNode>} nodes
@@ -148,18 +147,22 @@ function split(node) {
148147
/**
149148
* Use `child`, add `parent` as its first child, put the original children
150149
* into `parent`.
150+
* If `child` is not a parent, `parent` will not be added.
151151
*
152152
* @param {MdastNode} child
153153
* @returns {MdastNode}
154154
*/
155155
function onnonphrasing(child) {
156-
return Object.assign(shallow(child), {
157-
children: [
158-
Object.assign(extend(true, {}, shallow(node)), {
159-
children: 'children' in child ? child.children : []
160-
})
161-
]
162-
})
156+
if ('children' in child && 'children' in node) {
157+
const {children, ...rest} = node
158+
return {
159+
...child,
160+
// @ts-expect-error: assume matching parent & child.
161+
children: [{...extend(true, {}, rest), children: child.children}]
162+
}
163+
}
164+
165+
return {...child}
163166
}
164167

165168
/**
@@ -169,7 +172,10 @@ function split(node) {
169172
* @returns {MdastNode}
170173
*/
171174
function onphrasing(nodes) {
172-
return Object.assign(extend(true, {}, shallow(node)), {children: nodes})
175+
// @ts-expect-error: assume parent.
176+
const {children, ...rest} = node
177+
// @ts-expect-error: assume matching parent & child.
178+
return {...extend(true, {}, rest), children: nodes}
173179
}
174180
}
175181

test/fixtures/straddling/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ <h2>Overlap explicit</h2>
6565
</object>
6666
<p>I’m quite proud of it.</p>
6767
</section>
68+
69+
<section>
70+
<a href="#url">a<hr>b</a>
71+
</section>

test/fixtures/straddling/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ To see the cat simulator, use one of the following links:
5555
Alternatively, upgrade to the Mellblom Browser.
5656

5757
I’m quite proud of it.
58+
59+
[a](#url)
60+
61+
***
62+
63+
[b](#url)

0 commit comments

Comments
 (0)