@@ -2,12 +2,90 @@ import Alpine from 'alpinejs'
22import collapse from '@alpinejs/collapse'
33import persist from '@alpinejs/persist'
44import focus from '@alpinejs/focus'
5-
5+ import { marked } from 'marked'
6+ import hljs from 'highlight.js/lib/core'
7+ // Import languages relevant to Docker docs
8+ import bash from 'highlight.js/lib/languages/bash'
9+ import dockerfile from 'highlight.js/lib/languages/dockerfile'
10+ import yaml from 'highlight.js/lib/languages/yaml'
11+ import json from 'highlight.js/lib/languages/json'
12+ import javascript from 'highlight.js/lib/languages/javascript'
13+ import python from 'highlight.js/lib/languages/python'
14+ import go from 'highlight.js/lib/languages/go'
15+
616window . Alpine = Alpine
717
818Alpine . plugin ( collapse )
919Alpine . plugin ( persist )
1020Alpine . plugin ( focus )
21+
22+ // Register highlight.js languages
23+ hljs . registerLanguage ( 'bash' , bash )
24+ hljs . registerLanguage ( 'sh' , bash )
25+ hljs . registerLanguage ( 'shell' , bash )
26+ hljs . registerLanguage ( 'console' , bash )
27+ hljs . registerLanguage ( 'dockerfile' , dockerfile )
28+ hljs . registerLanguage ( 'yaml' , yaml )
29+ hljs . registerLanguage ( 'yml' , yaml )
30+ hljs . registerLanguage ( 'json' , json )
31+ hljs . registerLanguage ( 'javascript' , javascript )
32+ hljs . registerLanguage ( 'js' , javascript )
33+ hljs . registerLanguage ( 'python' , python )
34+ hljs . registerLanguage ( 'py' , python )
35+ hljs . registerLanguage ( 'go' , go )
36+ hljs . registerLanguage ( 'golang' , go )
37+
38+ // Add $markdown magic for rendering markdown with syntax highlighting
39+ Alpine . magic ( 'markdown' , ( ) => {
40+ return ( content ) => {
41+ if ( ! content ) return ''
42+ const html = marked ( content )
43+
44+ // Parse and highlight code blocks
45+ const div = document . createElement ( 'div' )
46+ div . innerHTML = html
47+
48+ // Handle code blocks (pre > code)
49+ div . querySelectorAll ( 'pre' ) . forEach ( ( pre ) => {
50+ // Add not-prose to prevent Tailwind Typography styling
51+ pre . classList . add ( 'not-prose' )
52+ const code = pre . querySelector ( 'code' )
53+ if ( code ) {
54+ // Preserve the original text with newlines
55+ const codeText = code . textContent
56+
57+ // Clear and set as plain text first to preserve structure
58+ code . textContent = codeText
59+
60+ // Now apply highlight.js which will work with the text nodes
61+ hljs . highlightElement ( code )
62+ }
63+ } )
64+
65+ // Handle inline code elements (not in pre blocks)
66+ div . querySelectorAll ( 'code:not(pre code)' ) . forEach ( ( code ) => {
67+ code . classList . add ( 'not-prose' )
68+ } )
69+
70+ return div . innerHTML
71+ }
72+ } )
73+
74+ // Stores
1175Alpine . store ( "showSidebar" , false )
76+ Alpine . store ( 'gordon' , {
77+ isOpen : Alpine . $persist ( false ) . as ( 'gordon-isOpen' ) ,
78+ query : '' ,
79+ toggle ( ) {
80+ this . isOpen = ! this . isOpen
81+ } ,
82+ open ( query ) {
83+ this . isOpen = true
84+ if ( query ) this . query = query
85+ } ,
86+ close ( ) {
87+ this . isOpen = false
88+ }
89+ } )
1290
1391Alpine . start ( )
0 commit comments