(content: string)
| 41 | } |
| 42 | |
| 43 | export function transformBlocks(content: string): { content: string; blocks: Map<string, MarkdownContentBlockType> } { |
| 44 | const lines = content.split("\n"); |
| 45 | const blocks = new Map(); |
| 46 | let currentBlock = null; |
| 47 | let currentContent = []; |
| 48 | let processedLines = []; |
| 49 | |
| 50 | for (const line of lines) { |
| 51 | // Check for start marker |
| 52 | if (line.startsWith("@@@start ")) { |
| 53 | // Already in a block? Add as content |
| 54 | if (currentBlock) { |
| 55 | processedLines.push(line); |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | // Parse the start line |
| 60 | const [, type, rest] = line.slice(9).match(/^(\w+)\s+(.*)/) || []; |
| 61 | if (!type || !rest) { |
| 62 | // Invalid format - treat as regular content |
| 63 | processedLines.push(line); |
| 64 | continue; |
| 65 | } |
| 66 | |
| 67 | // Get the ID (everything between first set of quotes) |
| 68 | const idMatch = rest.match(idMatchRe); |
| 69 | if (!idMatch) { |
| 70 | processedLines.push(line); |
| 71 | continue; |
| 72 | } |
| 73 | |
| 74 | // Parse options if any exist after the ID |
| 75 | const afterId = rest.slice(idMatch[0].length).trim(); |
| 76 | const opts = parseOptions(afterId); |
| 77 | |
| 78 | currentBlock = { |
| 79 | type, |
| 80 | id: idMatch[1], |
| 81 | opts, |
| 82 | }; |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | // Check for end marker |
| 87 | if (line.startsWith("@@@end ")) { |
| 88 | // If we're not in a block, treat as content |
| 89 | if (!currentBlock) { |
| 90 | processedLines.push(line); |
| 91 | continue; |
| 92 | } |
| 93 | |
| 94 | // Parse the end line |
| 95 | const [, type, rest] = line.slice(7).match(/^(\w+)\s+(.*)/) || []; |
| 96 | if (!type || !rest) { |
| 97 | currentContent.push(line); |
| 98 | continue; |
| 99 | } |
| 100 |
no test coverage detected