Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
@import "syntax-dark.css";
@import "syntax-light.css";
@import "components.css";
@import "highlight-github-dark.css";

@variant dark (&:where(.dark, .dark *));
80 changes: 79 additions & 1 deletion assets/js/src/alpine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,90 @@ import Alpine from 'alpinejs'
import collapse from '@alpinejs/collapse'
import persist from '@alpinejs/persist'
import focus from '@alpinejs/focus'

import { marked } from 'marked'
import hljs from 'highlight.js/lib/core'
// Import languages relevant to Docker docs
import bash from 'highlight.js/lib/languages/bash'
import dockerfile from 'highlight.js/lib/languages/dockerfile'
import yaml from 'highlight.js/lib/languages/yaml'
import json from 'highlight.js/lib/languages/json'
import javascript from 'highlight.js/lib/languages/javascript'
import python from 'highlight.js/lib/languages/python'
import go from 'highlight.js/lib/languages/go'

window.Alpine = Alpine

Alpine.plugin(collapse)
Alpine.plugin(persist)
Alpine.plugin(focus)

// Register highlight.js languages
hljs.registerLanguage('bash', bash)
hljs.registerLanguage('sh', bash)
hljs.registerLanguage('shell', bash)
hljs.registerLanguage('console', bash)
hljs.registerLanguage('dockerfile', dockerfile)
hljs.registerLanguage('yaml', yaml)
hljs.registerLanguage('yml', yaml)
hljs.registerLanguage('json', json)
hljs.registerLanguage('javascript', javascript)
hljs.registerLanguage('js', javascript)
hljs.registerLanguage('python', python)
hljs.registerLanguage('py', python)
hljs.registerLanguage('go', go)
hljs.registerLanguage('golang', go)

// Add $markdown magic for rendering markdown with syntax highlighting
Alpine.magic('markdown', () => {
return (content) => {
if (!content) return ''
const html = marked(content)

// Parse and highlight code blocks
const div = document.createElement('div')
div.innerHTML = html

// Handle code blocks (pre > code)
div.querySelectorAll('pre').forEach((pre) => {
// Add not-prose to prevent Tailwind Typography styling
pre.classList.add('not-prose')
const code = pre.querySelector('code')
if (code) {
// Preserve the original text with newlines
const codeText = code.textContent

// Clear and set as plain text first to preserve structure
code.textContent = codeText

// Now apply highlight.js which will work with the text nodes
hljs.highlightElement(code)
}
})

// Handle inline code elements (not in pre blocks)
div.querySelectorAll('code:not(pre code)').forEach((code) => {
code.classList.add('not-prose')
})

return div.innerHTML
}
})

// Stores
Alpine.store("showSidebar", false)
Alpine.store('gordon', {
isOpen: Alpine.$persist(false).as('gordon-isOpen'),
query: '',
toggle() {
this.isOpen = !this.isOpen
},
open(query) {
this.isOpen = true
if (query) this.query = query
},
close() {
this.isOpen = false
}
})

Alpine.start()
3 changes: 3 additions & 0 deletions hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ module:
# Mount the icon files to assets so we can access them with resources.Get
- source: node_modules/@material-symbols/svg-400/rounded
target: assets/icons
# Mount highlight.js theme for Gordon chat syntax highlighting
- source: node_modules/highlight.js/styles/github-dark.css
target: assets/css/highlight-github-dark.css

imports:

Expand Down
Loading
Loading