MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / transformBlocks

Function transformBlocks

frontend/app/element/markdown-util.ts:43–155  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

41}
42
43export 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

Callers 1

MarkdownFunction · 0.90

Calls 5

parseOptionsFunction · 0.85
makeMarkdownWaveBlockKeyFunction · 0.85
formatInlineContentBlockFunction · 0.85
pushMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected