MCPcopy Create free account
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 else:
111 return "All mermaid diagrams in file: " + relative_path + " are syntax correct"
112
113 except Exception as e:
114 return f"Error processing file: {str(e)}"
115
116
117def extract_mermaid_blocks(content: str) -> List[Tuple[int, str]]:
118 """
119 Extract all mermaid code blocks from markdown content.
120
121 Returns:
122 List of tuples containing (line_number, diagram_content)
123 """
124 mermaid_blocks = []
125 lines = content.split("\n")
126 i = 0
127
128 while i < len(lines):
129 line = lines[i].strip()
130
131 # Look for mermaid code block start
132 if line == "```mermaid" or line.startswith("```mermaid"):
133 start_line = i + 1
134 diagram_lines = []
135 i += 1
136
137 # Collect lines until we find the closing ```
138 while i < len(lines):
139 if lines[i].strip() == "```":
140 break
141 diagram_lines.append(lines[i])
142 i += 1
143
144 if diagram_lines: # Only add non-empty diagrams
145 diagram_content = "\n".join(diagram_lines)
146 mermaid_blocks.append((start_line, diagram_content))
147
148 i += 1

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected