// 验证 Markdown.tsx 的 parseBlocks 是否产出空内容 const INLINE = /^(\s*)([-*+]\s+|\d+[.)]\s+|>\s?|(#{1,3}\s+))?(.*)$/ function parseBlocks(text) { const blocks = [] const lines = text.split('\n') let current = null const flush = () => { if (current) blocks.push(current) current = null } for (const line of lines) { const m = line.match(INLINE) if (!m) continue const [, indent, marker, content] = m const isListItem = Boolean(marker && /^([-*+]\s+|\d+[.)]\s+)/.test(marker)) const kind = marker ? marker.startsWith('#') ? 'h1' : isListItem ? /^\d/.test(marker) ? 'ol' : 'ul' : marker.startsWith('>') ? 'quote' : null : 'p' if (kind === 'p') { if (!current || current.kind !== 'p') { flush() current = { kind: 'p', lines: [] } } current.lines.push(content) continue } flush() } return blocks } for (const t of ['pong', 'Hello world', '# 标题', '- 列表项', '> 引用', '1. 有序']) { const blocks = parseBlocks(t) const rendered = blocks.map((b) => b.lines.join('\n')) console.log(JSON.stringify(t), '->', JSON.stringify(rendered)) }