-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathp.js
30 lines (27 loc) · 789 Bytes
/
p.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @import {State} from 'hast-util-to-mdast'
* @import {Element} from 'hast'
* @import {Paragraph, PhrasingContent} from 'mdast'
*/
import {dropSurroundingBreaks} from '../util/drop-surrounding-breaks.js'
/**
* @param {State} state
* State.
* @param {Readonly<Element>} node
* hast element to transform.
* @returns {Paragraph | undefined}
* mdast node.
*/
export function p(state, node) {
const children = dropSurroundingBreaks(
// Allow potentially “invalid” nodes, they might be unknown.
// We also support straddling later.
/** @type {Array<PhrasingContent>} */ (state.all(node))
)
if (children.length > 0) {
/** @type {Paragraph} */
const result = {type: 'paragraph', children}
state.patch(node, result)
return result
}
}