(content, category, filename)
| 160 | } |
| 161 | |
| 162 | parseMarkdownContent(content, category, filename) { |
| 163 | const lines = content.split('\n'); |
| 164 | let title = ''; |
| 165 | let description = ''; |
| 166 | let htmlContent = ''; |
| 167 | let cssContent = ''; |
| 168 | let currentSection = ''; |
| 169 | let codeBlock = []; |
| 170 | let isInCodeBlock = false; |
| 171 | let codeBlockType = ''; |
| 172 | |
| 173 | for (let i = 0; i < lines.length; i++) { |
| 174 | const line = lines[i]; |
| 175 | |
| 176 | // 提取标题 |
| 177 | if (line.startsWith('## ') && !title) { |
| 178 | title = line.replace('## ', '').trim(); |
| 179 | continue; |
| 180 | } |
| 181 | |
| 182 | // 检测代码块开始 |
| 183 | if (line.startsWith('```')) { |
| 184 | if (!isInCodeBlock) { |
| 185 | // 开始代码块 |
| 186 | isInCodeBlock = true; |
| 187 | codeBlockType = line.replace('```', '').trim() || 'text'; |
| 188 | codeBlock = []; |
| 189 | } else { |
| 190 | // 结束代码块 |
| 191 | isInCodeBlock = false; |
| 192 | const code = codeBlock.join('\n'); |
| 193 | |
| 194 | if (codeBlockType === 'html' || codeBlockType.includes('html')) { |
| 195 | htmlContent += code + '\n\n'; |
| 196 | } else if (codeBlockType === 'css' || codeBlockType.includes('css')) { |
| 197 | cssContent += code + '\n\n'; |
| 198 | } |
| 199 | |
| 200 | codeBlock = []; |
| 201 | codeBlockType = ''; |
| 202 | } |
| 203 | continue; |
| 204 | } |
| 205 | |
| 206 | // 收集代码块内容 |
| 207 | if (isInCodeBlock) { |
| 208 | codeBlock.push(line); |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | // 收集描述信息 |
| 213 | if (!isInCodeBlock && line.trim() && !line.startsWith('#')) { |
| 214 | if (!description && title) { |
| 215 | description += line + ' '; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 |
no test coverage detected