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

Function markdown_to_html

codewiki/src/fe/visualise_docs.py:68–90  ·  view source on GitHub ↗

Convert markdown content to HTML, with special handling for mermaid diagrams.

(content: str)

Source from the content-addressed store, hash-verified

66
67
68def markdown_to_html(content: str) -> str:
69 """Convert markdown content to HTML, with special handling for mermaid diagrams."""
70 # First, convert markdown to HTML
71 html = md.render(content)
72
73 # Post-process to ensure mermaid code blocks are properly formatted
74 # Look for code blocks with language-mermaid class and convert them to mermaid divs
75 import re
76
77 # Pattern to match mermaid code blocks
78 pattern = r'<pre><code class="language-mermaid">(.*?)</code></pre>'
79
80 def replace_mermaid(match):
81 mermaid_code = match.group(1)
82 # Decode HTML entities that might have been encoded
83 import html
84 mermaid_code = html.unescape(mermaid_code)
85 return f'<div class="mermaid">{mermaid_code}</div>'
86
87 # Replace mermaid code blocks with proper mermaid divs
88 html = re.sub(pattern, replace_mermaid, html, flags=re.DOTALL)
89
90 return html
91
92
93def get_file_title(file_path: Path) -> str:

Callers 3

indexFunction · 0.85
serve_docFunction · 0.85
serve_generated_docsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected