(text)
| 251 | } |
| 252 | |
| 253 | function renderMarkdown(text) { |
| 254 | const lines = String(text).replace(/\r\n?/g, "\n").split("\n"); |
| 255 | const html = []; |
| 256 | let paragraphLines = []; |
| 257 | let quoteLines = []; |
| 258 | let listType = null; |
| 259 | let listItems = []; |
| 260 | |
| 261 | const flushParagraph = () => { |
| 262 | if (!paragraphLines.length) return; |
| 263 | html.push(`<p>${renderInlineMarkdown(paragraphLines.join(" "))}</p>`); |
| 264 | paragraphLines = []; |
| 265 | }; |
| 266 | |
| 267 | const flushQuote = () => { |
| 268 | if (!quoteLines.length) return; |
| 269 | const quoteBody = quoteLines.map((line) => renderInlineMarkdown(line)).join("<br />"); |
| 270 | html.push(`<blockquote><p>${quoteBody}</p></blockquote>`); |
| 271 | quoteLines = []; |
| 272 | }; |
| 273 | |
| 274 | const flushList = () => { |
| 275 | if (!listItems.length || !listType) return; |
| 276 | const items = listItems.map((item) => `<li>${renderInlineMarkdown(item)}</li>`).join(""); |
| 277 | html.push(`<${listType}>${items}</${listType}>`); |
| 278 | listType = null; |
| 279 | listItems = []; |
| 280 | }; |
| 281 | |
| 282 | const flushAll = () => { |
| 283 | flushParagraph(); |
| 284 | flushQuote(); |
| 285 | flushList(); |
| 286 | }; |
| 287 | |
| 288 | for (let index = 0; index < lines.length; index++) { |
| 289 | const line = lines[index]; |
| 290 | const trimmed = line.trim(); |
| 291 | |
| 292 | if (trimmed.startsWith("```")) { |
| 293 | flushAll(); |
| 294 | const language = trimmed.slice(3).trim(); |
| 295 | const codeLines = []; |
| 296 | index += 1; |
| 297 | while (index < lines.length && !lines[index].trim().startsWith("```")) { |
| 298 | codeLines.push(lines[index]); |
| 299 | index += 1; |
| 300 | } |
| 301 | const languageClass = language ? ` class="language-${escapeHtml(language)}"` : ""; |
| 302 | html.push(`<pre><code${languageClass}>${escapeHtml(codeLines.join("\n"))}</code></pre>`); |
| 303 | continue; |
| 304 | } |
| 305 | |
| 306 | if (!trimmed) { |
| 307 | flushAll(); |
| 308 | continue; |
| 309 | } |
| 310 |
no test coverage detected