1
1
/**
2
+ * @typedef {import('./types.js').Enter } Enter
3
+ * @typedef {import('./types.js').Info } Info
4
+ * @typedef {import('./types.js').Join } Join
5
+ * @typedef {import('./types.js').FlowContent } FlowContent
2
6
* @typedef {import('./types.js').Node } Node
3
7
* @typedef {import('./types.js').Options } Options
8
+ * @typedef {import('./types.js').Parent } Parent
9
+ * @typedef {import('./types.js').PhrasingContent } PhrasingContent
4
10
* @typedef {import('./types.js').State } State
5
- * @typedef {import('./types.js').Join } Join
6
- * @typedef {import('./types.js').Enter } Enter
11
+ * @typedef {import('./types.js').TrackFields } TrackFields
7
12
*/
8
13
9
14
import { zwitch } from 'zwitch'
10
15
import { configure } from './configure.js'
11
16
import { handle as handlers } from './handle/index.js'
12
17
import { join } from './join.js'
13
18
import { unsafe } from './unsafe.js'
19
+ import { containerPhrasing } from './util/container-phrasing.js'
20
+ import { containerFlow } from './util/container-flow.js'
14
21
import { indentLines } from './util/indent-lines.js'
15
22
16
23
/**
@@ -28,6 +35,8 @@ export function toMarkdown(tree, options = {}) {
28
35
const state = {
29
36
enter,
30
37
indentLines,
38
+ containerPhrasing : containerPhrasingBound ,
39
+ containerFlow : containerFlowBound ,
31
40
stack : [ ] ,
32
41
unsafe : [ ] ,
33
42
join : [ ] ,
@@ -104,3 +113,40 @@ function joinDefinition(left, right) {
104
113
return 0
105
114
}
106
115
}
116
+
117
+ /**
118
+ * Serialize the children of a parent that contains phrasing children.
119
+ *
120
+ * These children will be joined flush together.
121
+ *
122
+ * @this {State}
123
+ * Info passed around about the current state.
124
+ * @param {Parent & {children: Array<PhrasingContent>} } parent
125
+ * Parent of flow nodes.
126
+ * @param {Info } info
127
+ * Info on where we are in the document we are generating.
128
+ * @returns {string }
129
+ * Serialized children, joined together.
130
+ */
131
+ function containerPhrasingBound ( parent , info ) {
132
+ return containerPhrasing ( parent , this , info )
133
+ }
134
+
135
+ /**
136
+ * Serialize the children of a parent that contains flow children.
137
+ *
138
+ * These children will typically be joined by blank lines.
139
+ * What they are joined by exactly is defined by `Join` functions.
140
+ *
141
+ * @this {State}
142
+ * Info passed around about the current state.
143
+ * @param {Parent & {children: Array<FlowContent>} } parent
144
+ * Parent of flow nodes.
145
+ * @param {TrackFields } info
146
+ * Info on where we are in the document we are generating.
147
+ * @returns {string }
148
+ * Serialized children, joined by (blank) lines.
149
+ */
150
+ function containerFlowBound ( parent , info ) {
151
+ return containerFlow ( parent , this , info )
152
+ }
0 commit comments