|
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
7 | 7 | <meta name="description" content="FastProto documentation: annotation mapping, byte/bit order, checksum/CRC, formulas, arrays & strings, APIs without annotations, FAQ."> |
8 | 8 | <link rel="icon" href="../logo.png"> |
| 9 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github.min.css" data-hljs-theme> |
9 | 10 | <style> |
10 | 11 | :root{ |
11 | 12 | --bg:#f7f9fc; --card:#ffffff; --text:#111; --muted:#4a5568; --brand:#2563eb; --accent:#059669; |
|
60 | 61 | body{margin:0} |
61 | 62 | </style> |
62 | 63 | <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> |
| 64 | + <script src="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/lib/highlight.min.js"></script> |
63 | 65 | <script> |
64 | 66 | // Fallback loader for marked.js if primary CDN blocked |
65 | 67 | (function(){ |
|
69 | 71 | s.src=src; s.onload=resolve; s.onerror=reject; document.head.appendChild(s); |
70 | 72 | }); |
71 | 73 | } |
| 74 | + function loadCss(href){ |
| 75 | + return new Promise(function(resolve,reject){ |
| 76 | + var l=document.createElement('link'); |
| 77 | + l.rel='stylesheet'; l.href=href; l.onload=resolve; l.onerror=reject; |
| 78 | + document.head.appendChild(l); |
| 79 | + }); |
| 80 | + } |
| 81 | + function ensureHljsTheme(){ |
| 82 | + if(document.querySelector('link[data-hljs-theme]')) return; |
| 83 | + var themeLink=document.createElement('link'); |
| 84 | + themeLink.rel='stylesheet'; |
| 85 | + themeLink.href='https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github.min.css'; |
| 86 | + themeLink.setAttribute('data-hljs-theme',''); |
| 87 | + document.head.appendChild(themeLink); |
| 88 | + } |
72 | 89 | window.ensureMarked = async function(){ |
73 | 90 | if(window.marked) return; |
74 | 91 | try{ await loadScript('https://unpkg.com/marked/marked.min.js'); }catch(e){} |
75 | 92 | if(window.marked) return; |
76 | 93 | try{ await loadScript('https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.2/marked.min.js'); }catch(e){} |
77 | 94 | }; |
| 95 | + window.ensureHljs = async function(){ |
| 96 | + if(window.hljs) return; |
| 97 | + ensureHljsTheme(); |
| 98 | + try{ |
| 99 | + await loadScript('https://unpkg.com/highlight.js@11.9.0/lib/highlight.min.js'); |
| 100 | + return; |
| 101 | + }catch(e){} |
| 102 | + try{ |
| 103 | + await loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js'); |
| 104 | + return; |
| 105 | + }catch(e){} |
| 106 | + try{ |
| 107 | + await loadCss('https://unpkg.com/highlight.js@11.9.0/styles/github.min.css'); |
| 108 | + }catch(e){} |
| 109 | + try{ |
| 110 | + await loadCss('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css'); |
| 111 | + }catch(e){} |
| 112 | + }; |
78 | 113 | })(); |
79 | 114 | </script> |
80 | 115 | </head> |
@@ -174,6 +209,10 @@ <h3>Guides</h3> |
174 | 209 | if(!window.marked){ await window.ensureMarked(); } |
175 | 210 | if(window.marked){ |
176 | 211 | docEl.innerHTML = marked.parse(md, { breaks: true }); |
| 212 | + if(!window.hljs){ await window.ensureHljs(); } |
| 213 | + if(window.hljs){ |
| 214 | + docEl.querySelectorAll('pre code').forEach(block => window.hljs.highlightElement(block)); |
| 215 | + } |
177 | 216 | }else{ |
178 | 217 | docEl.innerHTML = '<pre>'+ escapeHtml(md) +'</pre>'; |
179 | 218 | } |
|
0 commit comments