Skip to content

Instantly share code, notes, and snippets.

@sjorsrijsdam
sjorsrijsdam / README.MD
Last active February 23, 2024 17:39
Server-side code highlighting for Enhance.dev

Server-side highlighting of code in HTML

Basically you place you code examples in your HTML code in the <code-example> custom element with a language attribute for the language. Then, in the API handler you run the entire HTML blob through the highlightCode() function. This will use the existing @begin/parse5 package to parse the HTML. It will then traverse the DOM tree, find the <code-example> elements, do PrismJS magic on its contents and then places them back. At the custom element expansion stage the highlighted code gets put in the <pre> & <code> and adds the correct class name based on the language attribute of the <code-example> element.


Screenshot 2024-02-23 141917
@sjorsrijsdam
sjorsrijsdam / d-bug.mjs
Last active November 28, 2023 19:14
Custom Enhance element to be able to debug view state
// Custom Enhance element to debug/inspect the `state` property
// that is passed to Enhance views.
//
// Optional `key` attribute can be used to inspect from
// a desired depth.
//
// Default styling is Monokai Midnight, but can be overridden
// by changing the various custom properties.
//
// Usage:
@sjorsrijsdam
sjorsrijsdam / mootools-ie11-patch
Created November 13, 2013 15:50
Quick and dirty hack to monkey patch Mootools and stop IE11 from crapping itself.
// Add this to mootool core just before
// Browser[Browser.name] = true;
// Browser[Browser.name + parseInt(Browser.version, 10)] = true;
// Browser.Platform[Browser.Platform.name] = true;
if (ua.indexOf('trident/7.0') > -1) {
Browser.name = 'ie';
Browser.version = '11';
}