bohdan

Finished
22 return `<${tag}>${text}</${tag}>`;
33}
44
5function isTag(text, tag) {
6 return text.startsWith(`<${tag}>`);
7}
5// Refactored: Removed unused isTag function
6
7// Refactored: Added MarkdownLineType for better code readability
8const MarkdownLineType = {
9 HEADER: 'header',
10 LIST_ITEM: 'list_item',
11 PARAGRAPH: 'paragraph'
12};
813
914function parser(markdown, delimiter, tag) {
1015 const pattern = new RegExp(`${delimiter}(.+)${delimiter}`);
1217 return markdown.replace(pattern, replacement);
1318}
1419
15function parse__(markdown) {
20// Refactored: Renamed parse__ to parseBoldText for clarity
21function parseBoldText(markdown) {
1622 return parser(markdown, '__', 'strong');
1723}
1824
19function parse_(markdown) {
25// Refactored: Renamed parse_ to parseItalicText for clarity
26function parseItalicText(markdown) {
2027 return parser(markdown, '_', 'em');
2128}
2229
30// Refactored: Updated to use renamed functions
2331function parseText(markdown, list) {
24 const parsedText = parse_(parse__(markdown));
32 const parsedText = parseItalicText(parseBoldText(markdown));
2533 if (list) {
2634 return parsedText;
2735 } else {
7078 }
7179}
7280
81// Refactored: Simplified control flow with early returns and improved error message
7382function parseLine(markdown, list) {
83 // Try to parse as header
7484 let [result, inListAfter] = parseHeader(markdown, list);
75 if (result === null) {
76 [result, inListAfter] = parseLineItem(markdown, list);
85 if (result !== null) {
86 return [result, inListAfter];
7787 }
78 if (result === null) {
79 [result, inListAfter] = parseParagraph(markdown, list);
88
89 // Try to parse as list item
90 [result, inListAfter] = parseLineItem(markdown, list);
91 if (result !== null) {
92 return [result, inListAfter];
8093 }
81 if (result === null) {
82 throw new Error('Remove this line and implement the function');
94
95 // Parse as paragraph (fallback)
96 [result, inListAfter] = parseParagraph(markdown, list);
97 if (result !== null) {
98 return [result, inListAfter];
8399 }
84 return [result, inListAfter];
100
101 // This should never happen as parseParagraph always returns a result
102 throw new Error('Failed to parse markdown line: ' + markdown);
85103}
86104
105// Refactored: Extracted list state management to helper function
87106/**
88107 * @param {string} markdown
89108 * @returns {string}
97116 result += lineResult;
98117 list = newList;
99118 }
119 return finalizeList(result, list);
120}
121
122// Refactored: Moved helper function closer to where it's used
123function finalizeList(result, list) {
100124 if (list) {
101125 return result + '</ul>';
102126 } else {
Test NameStatus
parses normal text as a paragraph
Pass
parsing italics
Pass
parsing bold text
Pass
mixed normal, italics and bold text
Pass
with h1 header level
Pass
with h2 header level
Pass
with h3 header level
Pass
with h4 header level
Pass
with h5 header level
Pass
with h6 header level
Pass
with h7 header level
Pass
unordered lists
Pass
with a little bit of everything
Pass
with markdown symbols in the header text that should not be interpreted
Pass
with markdown symbols in the list item text that should not be interpreted
Pass
with markdown symbols in the paragraph text that should not be interpreted
Pass
unordered lists close properly with preceding and following lines
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.