import type { Action } from 'svelte/action'; import { highlightElement } from './highlight'; /** * Highlight code in any child `
` blocks. * Elements should be styled according to Highlight.js's expected HTML structure. * highlighting only runs on mount of the element, so the element using the action should be a keyed element to force re-highlighting on updates. * * Usage example: * ```svelte * * * {#key code} *
*
{code}
*
* {/key} * ``` * * @param node - The node to highlight. */ export const highlightCode: Action = ( node: HTMLElement | undefined ) => { if (node) { if (node.tagName === 'PRE') { const codeElement = node.querySelector('code'); if (codeElement) { highlightElement(codeElement); } } else { highlightElement(node); } } };