(markdown)
| 124 | } |
| 125 | |
| 126 | function renderMarkdown(markdown) { |
| 127 | const lines = String(markdown || "").replace(/\r\n/g, "\n").split("\n"); |
| 128 | const out = []; |
| 129 | let paragraph = []; |
| 130 | let listItems = []; |
| 131 | let listType = ""; |
| 132 | let quoteLines = []; |
| 133 | let inCode = false; |
| 134 | let codeLines = []; |
| 135 | |
| 136 | const flushParagraph = () => { |
| 137 | if (!paragraph.length) return; |
| 138 | out.push(`<p>${renderInlineMarkdown(paragraph.join(" "))}</p>`); |
| 139 | paragraph = []; |
| 140 | }; |
| 141 | const flushList = () => { |
| 142 | if (!listItems.length) return; |
| 143 | out.push(`<${listType}>${listItems.map((item) => `<li>${renderInlineMarkdown(item)}</li>`).join("")}</${listType}>`); |
| 144 | listItems = []; |
| 145 | listType = ""; |
| 146 | }; |
| 147 | const flushQuote = () => { |
| 148 | if (!quoteLines.length) return; |
| 149 | out.push(`<blockquote>${quoteLines.map((item) => `<p>${renderInlineMarkdown(item)}</p>`).join("")}</blockquote>`); |
| 150 | quoteLines = []; |
| 151 | }; |
| 152 | const flushCode = () => { |
| 153 | if (!inCode) return; |
| 154 | out.push(`<pre><code>${window.escapeHtml ? window.escapeHtml(codeLines.join("\n")) : codeLines.join("\n")}</code></pre>`); |
| 155 | inCode = false; |
| 156 | codeLines = []; |
| 157 | }; |
| 158 | |
| 159 | for (const rawLine of lines) { |
| 160 | const line = rawLine.replace(/\t/g, " "); |
| 161 | const trimmed = line.trim(); |
| 162 | if (trimmed.startsWith("```")) { |
| 163 | flushParagraph(); |
| 164 | flushList(); |
| 165 | flushQuote(); |
| 166 | if (inCode) flushCode(); |
| 167 | else { |
| 168 | inCode = true; |
| 169 | codeLines = []; |
| 170 | } |
| 171 | continue; |
| 172 | } |
| 173 | if (inCode) { |
| 174 | codeLines.push(line); |
| 175 | continue; |
| 176 | } |
| 177 | if (!trimmed) { |
| 178 | flushParagraph(); |
| 179 | flushList(); |
| 180 | flushQuote(); |
| 181 | continue; |
| 182 | } |
| 183 | const heading = trimmed.match(/^(#{1,6})\s+(.*)$/); |
no test coverage detected