MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / extract_mermaid_blocks

Function extract_mermaid_blocks

codewiki/src/be/utils.py:112–145  ·  view source on GitHub ↗

Extract all mermaid code blocks from markdown content. Returns: List of tuples containing (line_number, diagram_content)

(content: str)

Source from the content-addressed store, hash-verified

110
111
112def extract_mermaid_blocks(content: str) -> List[Tuple[int, str]]:
113 """
114 Extract all mermaid code blocks from markdown content.
115
116 Returns:
117 List of tuples containing (line_number, diagram_content)
118 """
119 mermaid_blocks = []
120 lines = content.split('\n')
121 i = 0
122
123 while i < len(lines):
124 line = lines[i].strip()
125
126 # Look for mermaid code block start
127 if line == '```mermaid' or line.startswith('```mermaid'):
128 start_line = i + 1
129 diagram_lines = []
130 i += 1
131
132 # Collect lines until we find the closing ```
133 while i < len(lines):
134 if lines[i].strip() == '```':
135 break
136 diagram_lines.append(lines[i])
137 i += 1
138
139 if diagram_lines: # Only add non-empty diagrams
140 diagram_content = '\n'.join(diagram_lines)
141 mermaid_blocks.append((start_line, diagram_content))
142
143 i += 1
144
145 return mermaid_blocks
146
147
148# PythonMonkey 1.3.1 only supports Python 3.8–3.11. On 3.12+ it still imports,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected