Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
19 changes: 19 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,23 @@ import "@hotwired/turbo-rails"
import "actions"
import "controllers"
import "house"
import mermaid from "mermaid"

const MERMAID_KEYWORDS = /^(flowchart|graph|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|gitGraph|mindmap|timeline|sankey|xychart|block)\b/

mermaid.initialize({ startOnLoad: false, theme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "default" })

document.addEventListener("turbo:load", () => {
const targets = [...document.querySelectorAll("code.language-mermaid, pre.highlight.plaintext > code")]
.filter(el => el.classList.contains("language-mermaid") || MERMAID_KEYWORDS.test(el.textContent.trim()))
if (!targets.length) return
Comment thread
mprokopov marked this conversation as resolved.
Outdated
Comment thread
mprokopov marked this conversation as resolved.
Outdated

targets.forEach(el => {
const div = document.createElement("div")
div.className = "mermaid"
div.textContent = el.textContent
el.closest("pre").replaceWith(div)
Comment thread
mprokopov marked this conversation as resolved.
Outdated
})
mermaid.run()
Comment on lines +18 to +26
})

1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
pin "house", to: "house.min.js"

pin_all_from "app/javascript/actions", under: "actions"
pin "mermaid", to: "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs"
Comment thread
mprokopov marked this conversation as resolved.
Outdated
pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from "app/javascript/helpers", under: "helpers"
pin_all_from "app/javascript/lib", under: "lib"
Binary file added mermaid-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading