| 28 | } |
| 29 | |
| 30 | function postProcessHtml(html: string): string { |
| 31 | // Add language labels to highlighted code blocks |
| 32 | html = html.replace( |
| 33 | /<pre><code class="hljs language-(\w+)">/g, |
| 34 | '<pre class="code-block" data-language="$1"><code class="hljs language-$1">' |
| 35 | ); |
| 36 | |
| 37 | // Wrap plain pre>code (ASCII art / diagrams) in diagram container |
| 38 | html = html.replace( |
| 39 | /<pre><code(?! class="hljs)([^>]*)>/g, |
| 40 | '<pre class="ascii-diagram"><code$1>' |
| 41 | ); |
| 42 | |
| 43 | // Keep wide Markdown tables inside the prose column on small screens. |
| 44 | html = html.replace(/<table>/g, '<div class="table-scroll"><table>'); |
| 45 | html = html.replace(/<\/table>/g, '</table></div>'); |
| 46 | |
| 47 | // Mark the first blockquote as hero callout |
| 48 | html = html.replace( |
| 49 | /<blockquote>/, |
| 50 | '<blockquote class="hero-callout">' |
| 51 | ); |
| 52 | |
| 53 | // Remove the h1 (it's redundant with the page header) |
| 54 | html = html.replace(/<h1>.*?<\/h1>\n?/, ""); |
| 55 | |
| 56 | // Fix ordered list counter for interrupted lists (ol start="N") |
| 57 | html = html.replace( |
| 58 | /<ol start="(\d+)">/g, |
| 59 | (_, start) => `<ol style="counter-reset:step-counter ${parseInt(start) - 1}">` |
| 60 | ); |
| 61 | |
| 62 | return html; |
| 63 | } |
| 64 | |
| 65 | export function DocRenderer({ version }: DocRendererProps) { |
| 66 | const locale = useLocale(); |