Liking cljdoc? Tell your friends :D

baredom.components.x-code.model

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).
raw docstring

attr-codecljs

source

attr-expandedcljs

source

attr-filenamecljs

source

attr-languagecljs

source

attr-line-numberscljs

source

attr-max-linescljs

source

attr-show-copycljs

source

attr-wrapcljs

source

collapsible?cljs

(collapsible? max-lines line-count)

True when max-lines is positive and the code has more lines than that.

True when `max-lines` is positive and the code has more lines than that.
sourceraw docstring

css-prefixcljs

source

dedentcljs

(dedent s)

Remove the longest run of leading whitespace shared by every non-blank line. Lets authors indent slotted code to match surrounding markup without that indentation showing up in the rendered block.

Remove the longest run of leading whitespace shared by every non-blank
line. Lets authors indent slotted code to match surrounding markup
without that indentation showing up in the rendered block.
sourceraw docstring

default-languagecljs

source

default-max-linescljs

source

event-copycljs

source

event-schemacljs

source

event-togglecljs

source

lang-csscljs

source

lang-htmlcljs

source

lang-jscljs

source

lang-jsoncljs

source

lang-textcljs

source

language-labelcljs

(language-label language)

Short uppercase badge for a language, or "" for plain text.

Short uppercase badge for a language, or "" for plain text.
sourceraw docstring

method-apicljs

source

normalizecljs

(normalize {:keys [code-raw language-raw filename-raw show-copy? line-numbers?
                   wrap? max-lines-raw expanded? lines]})

Normalise raw inputs into the render-ready view-model.

Input keys: :code-raw string | nil (already resolved from property/attr/text) :language-raw string | nil :filename-raw string | nil :show-copy? boolean :line-numbers? boolean :wrap? boolean :max-lines-raw string | nil :expanded? boolean :lines optional precomputed per-line tokens. When supplied (a caller holding a tokenization for the same code + language) the tokenizer is skipped; otherwise :lines is computed from code + language.

Output keys: :code prepared code string :language canonical language id :language-label uppercase badge | "" :filename trimmed filename | "" :show-copy? boolean :line-numbers? boolean :wrap? boolean :max-lines int >= 0 :expanded? boolean :line-count int :lines [[[type text] ...] ...] per-line tokens :collapsible? boolean :header? boolean

Normalise raw inputs into the render-ready view-model.

Input keys:
  :code-raw       string | nil   (already resolved from property/attr/text)
  :language-raw   string | nil
  :filename-raw   string | nil
  :show-copy?     boolean
  :line-numbers?  boolean
  :wrap?          boolean
  :max-lines-raw  string | nil
  :expanded?      boolean
  :lines          optional precomputed per-line tokens. When supplied
                  (a caller holding a tokenization for the same code +
                  language) the tokenizer is skipped; otherwise :lines is
                  computed from code + language.

Output keys:
  :code            prepared code string
  :language        canonical language id
  :language-label  uppercase badge | ""
  :filename        trimmed filename | ""
  :show-copy?      boolean
  :line-numbers?   boolean
  :wrap?           boolean
  :max-lines       int >= 0
  :expanded?       boolean
  :line-count      int
  :lines           [[[type text] ...] ...]  per-line tokens
  :collapsible?    boolean
  :header?         boolean
sourceraw docstring

observed-attributescljs

source

parse-languagecljs

(parse-language s)

Canonicalise a language attribute. Aliases map onto js/json/css/html; anything unknown (including nil) becomes text.

Canonicalise a `language` attribute. Aliases map onto js/json/css/html;
anything unknown (including nil) becomes `text`.
sourceraw docstring

parse-max-linescljs

(parse-max-lines s)

Parse the max-lines attribute into a non-negative integer. 0 (the default for nil / non-numeric / non-positive input) means no collapsing.

Parse the `max-lines` attribute into a non-negative integer. 0 (the
default for nil / non-numeric / non-positive input) means no collapsing.
sourceraw docstring

prepare-codecljs

(prepare-code s)

Normalise raw code for display: convert CRLF / CR line endings to LF, drop leading/trailing blank lines, then strip common indentation. Non-string input becomes the empty string.

Normalise raw code for display: convert CRLF / CR line endings to LF, drop
leading/trailing blank lines, then strip common indentation. Non-string
input becomes the empty string.
sourceraw docstring

property-apicljs

source

tag-namecljs

source

tokenizecljs

(tokenize language code)

Tokenize code for language into a flat [[type text] ...] vector. The text language and any unknown language degrade to a single :plain token spanning the whole input.

Tokenize `code` for `language` into a flat [[type text] ...] vector.
The `text` language and any unknown language degrade to a single :plain
token spanning the whole input.
sourceraw docstring

tokens->linescljs

(tokens->lines tokens)

Split a flat token vector into per-line token vectors. A token whose text spans newlines is split so each line carries only its own slice.

Split a flat token vector into per-line token vectors. A token whose text
spans newlines is split so each line carries only its own slice.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close