Pure model layer for x-code — a code-display component with an in-house, regex-based syntax tokenizer.
No DOM, no side effects. Every function here is a plain data transform and is exercised directly by model_test.cljs with sparse inputs.
The tokenizer is deliberately lightweight. It covers js / json / css / html only and degrades any other language to plain text. It is a highlighter, not a parser: it does not track nested languages, and a handful of context-sensitive cases are knowingly imperfect (see docs/x-code.md).
Pure model layer for x-code — a code-display component with an in-house, regex-based syntax tokenizer. No DOM, no side effects. Every function here is a plain data transform and is exercised directly by model_test.cljs with sparse inputs. The tokenizer is deliberately lightweight. It covers js / json / css / html only and degrades any other language to plain text. It is a highlighter, not a parser: it does not track nested languages, and a handful of context-sensitive cases are knowingly imperfect (see docs/x-code.md).
DOM + lifecycle layer for x-code — a code-display component.
The component is stateless: DOM = f(attributes, properties). Source code is
read from the element's light-DOM textContent (or the code property /
attribute), tokenized by the pure model layer, and rendered escaped into
the shadow <code>. A MutationObserver re-renders when the light-DOM text
changes. The expand/collapse state lives in the observed expanded
attribute, so it too is a value, never a mutable field.
Instance fields hold only the refs map, the cached model, the
MutationObserver, and the code property override.
DOM + lifecycle layer for x-code — a code-display component. The component is stateless: DOM = f(attributes, properties). Source code is read from the element's light-DOM textContent (or the `code` property / attribute), tokenized by the pure model layer, and rendered escaped into the shadow `<code>`. A MutationObserver re-renders when the light-DOM text changes. The expand/collapse state lives in the observed `expanded` attribute, so it too is a value, never a mutable field. Instance fields hold only the refs map, the cached model, the MutationObserver, and the `code` property override.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |