Convert markdown content to HTML, with special handling for mermaid diagrams.
(content: str)
| 66 | |
| 67 | |
| 68 | def 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 | |
| 93 | def get_file_title(file_path: Path) -> str: |
no outgoing calls
no test coverage detected