Skip to content

v0.4.0

Choose a tag to compare

@omartelo omartelo released this 15 Oct 15:53
· 15 commits to main since this release

Changed

  • CSS, Go, HTML, Java, JavaScript, TypeScript, Python and Rust are
    highlighted by a port of CodeMirror's own Lezer parser.
    A file of one of
    them is parsed with its @lezer/* grammar and tagged by its styleTags, as
    CodeMirror tags it: a call and a declaration, a type and a variable, are told
    apart where chroma could not, and HTML's scripts, styles and style/on*
    attributes are highlighted as JavaScript and CSS. Code a grammar cannot
    parse is left as CodeMirror leaves it.
  • Kotlin and shell scripts are highlighted as CodeMirror highlights them,
    by a port of the @codemirror/legacy-modes modes (kotlin, shell) that
    CodeMirror runs through its StreamLanguage: .kt, .kts, .sh, .ksh,
    .bash and a file named PKGBUILD. Every other language is still read by
    chroma.
  • New content in a Lezer language is reparsed incrementally. SetContent
    and UpdateContent reuse the tree of the content before, as CodeMirror
    reparses after an edit, nested scripts and styles included: a one-character
    edit to 13,000 lines of Java reparses in about 1.2 ms instead of 50 ms, and
    the whole update takes about 28 ms instead of 78; in a 13,000-line HTML page,
    0.4 ms instead of 71, and 30 ms instead of 102. Highlighting now runs one
    content at a time, in order, skipping one replaced before its turn.
  • A token can carry several tags, and its style merges theirs. Each tag
    takes the spec of its most specific styled tag, and the specs apply in
    their order in the HighlightStyle, a later one's color, bold, italic,
    underline or line-through winning, as CSS cascades CodeMirror's classes. A
    chroma token still has one tag, and draws as before.