Files
Yassine Guedidi e341b62835 Skip repeat syntax highlighting on reconnect
Limit highlight.js work to code blocks that do not already carry the
`data-highlighted` marker set by `highlightElement()`.

This lets cached DOM reconnect cleanly without reprocessing the same block or
logging redundant work on repeat visits.
2026-04-05 16:17:13 +02:00

12 lines
333 B
JavaScript

import { Controller } from '@hotwired/stimulus';
import 'highlight.js/styles/atom-one-light.css';
import hljs from 'highlight.js';
export default class extends Controller {
connect() {
this.element.querySelectorAll('pre code:not([data-highlighted])').forEach((element) => {
hljs.highlightElement(element);
});
}
}