googlearchive / code-prettify

An embeddable script that makes source-code snippets in HTML prettier.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Kotlin] numbers are highlighted incorrectly in function names

vanniktech opened this issue · comments

The following:

interface Foo {
  fun bar1()
}

will not be highlighted correctly:

screenshot from 2018-06-15 16-08-48

commented

First I have to point out that code-prettify is a regex-based syntax highlighter, it does not implement a full parser for each language it supports. This is what makes it lightweight and fast, and by default works decently for a range of languages even ones not explicitly defined (most C-like or HTML-like languages). But it also means it will have false-positives and will fail in certain cases that only a full parser could handle (e.g contextual keywords, or string interpolation which is difficult to do right with regexps alone).


Now of the four kotlin issues you opened, I think this is the only one considered a bug, the rest works by-design:

  • #548: bug indeed, bar1 should indeed by tagged as one token "plain".
  • #549: as you can see in #496 (where kotlin language handler was added), author explicitly states that string interpolation is not handled. The same limitation exist for most other languages, if not all.
  • #550: lang-kotlin.js will tag anything starting with @ (annotation) as PR_LITERAL. If you'd like a different color, just apply a css-rule.
  • #551: also works as intended. Variable and functions names and such are tagged as PR_PLAIN.

For the above bug, maybe we should ping the author @mibac138 for a fix.

https://jsfiddle.net/2va6gjnq/