Skip to content

Commit 6d6886a

Browse files
authored
Merge pull request #30 from hiro08gh/add-comment
Add comment
2 parents 9d4a564 + 517ed55 commit 6d6886a

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/convert-dom-to-markdown.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ import {
2020
isTextElement,
2121
} from "./utils";
2222

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+
*/
2330
const convertDOMToMarkdown = ({
2431
nodes,
2532
image,
@@ -53,14 +60,20 @@ const convertDOMToMarkdown = ({
5360
};
5461

5562
/**
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.
5766
*/
5867
const convertTextNode = (node: Text): string => {
5968
return node.data;
6069
};
6170

6271
/**
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.
6477
*/
6578
const convertTagNode = (
6679
node: Element,
@@ -202,7 +215,11 @@ const convertTagNode = (
202215
};
203216

204217
/**
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.
206223
*/
207224
const getRecursionMarks = (
208225
node: Element,
@@ -228,14 +245,22 @@ const getRecursionMarks = (
228245
};
229246

230247
/**
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.
232251
*/
233252
const getChildNodeClass = (node: Element) => {
234253
return node.children
235254
.map((child) => (child.type === "tag" ? child.attribs.class : undefined))
236255
.filter(Boolean);
237256
};
238257

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+
*/
239264
const buildImageUrl = (
240265
node: Element,
241266
image: { size?: boolean; query?: string },
@@ -259,6 +284,12 @@ const buildImageUrl = (
259284
return url.href;
260285
};
261286

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+
*/
262293
const findDepth = (node: Element, currentDepth = 0): number => {
263294
const depth = currentDepth;
264295

0 commit comments

Comments
 (0)