@@ -20,6 +20,13 @@ import {
20
20
isTextElement ,
21
21
} from "./utils" ;
22
22
23
+ /**
24
+ * Converts an array of DOM nodes into a Markdown string.
25
+ * @param nodes - Array of DOM nodes to convert.
26
+ * @param image - Image conversion options.
27
+ * @param markStyle - Style options for Markdown formatting.
28
+ * @returns The generated Markdown string.
29
+ */
23
30
const convertDOMToMarkdown = ( {
24
31
nodes,
25
32
image,
@@ -53,14 +60,20 @@ const convertDOMToMarkdown = ({
53
60
} ;
54
61
55
62
/**
56
- * Get text in DOMNode
63
+ * Converts a text node into a Markdown string.
64
+ * @param node - The text node to convert.
65
+ * @returns The text content as a string.
57
66
*/
58
67
const convertTextNode = ( node : Text ) : string => {
59
68
return node . data ;
60
69
} ;
61
70
62
71
/**
63
- * Converts HTML tags to marks
72
+ * Converts an HTML element node into Markdown based on its type.
73
+ * @param node - The HTML element node to convert.
74
+ * @param image - Image conversion options.
75
+ * @param markStyle - Style options for Markdown formatting.
76
+ * @returns The generated Markdown string for the element.
64
77
*/
65
78
const convertTagNode = (
66
79
node : Element ,
@@ -202,7 +215,11 @@ const convertTagNode = (
202
215
} ;
203
216
204
217
/**
205
- * Recursively process convertDOMToMarkdown to get the markdown string
218
+ * Recursively processes DOM nodes to generate a Markdown string.
219
+ * @param node - The parent DOM element.
220
+ * @param image - Image conversion options.
221
+ * @param markStyle - Style options for Markdown formatting.
222
+ * @returns The concatenated Markdown string for the children.
206
223
*/
207
224
const getRecursionMarks = (
208
225
node : Element ,
@@ -228,14 +245,22 @@ const getRecursionMarks = (
228
245
} ;
229
246
230
247
/**
231
- * Get child node class.
248
+ * Extracts the class names of a node's children.
249
+ * @param node - The DOM element.
250
+ * @returns An array of class names.
232
251
*/
233
252
const getChildNodeClass = ( node : Element ) => {
234
253
return node . children
235
254
. map ( ( child ) => ( child . type === "tag" ? child . attribs . class : undefined ) )
236
255
. filter ( Boolean ) ;
237
256
} ;
238
257
258
+ /**
259
+ * Builds an image URL with optional size and query parameters.
260
+ * @param node - The image DOM element.
261
+ * @param image - Image conversion options (size and query parameters).
262
+ * @returns The constructed image URL.
263
+ */
239
264
const buildImageUrl = (
240
265
node : Element ,
241
266
image : { size ?: boolean ; query ?: string } ,
@@ -259,6 +284,12 @@ const buildImageUrl = (
259
284
return url . href ;
260
285
} ;
261
286
287
+ /**
288
+ * Calculates the nesting depth of a list element.
289
+ * @param node - The list element.
290
+ * @param currentDepth - The current depth (default is 0).
291
+ * @returns The calculated depth.
292
+ */
262
293
const findDepth = ( node : Element , currentDepth = 0 ) : number => {
263
294
const depth = currentDepth ;
264
295
0 commit comments