Skip to main content
12 events
when toggle format what by license comment
Oct 8, 2020 at 13:52 comment added Konrad Rudolph Anyway, splitting the C and C++ tokenisers would allow us to get at least C 100% right, and I’m working on it.
Oct 8, 2020 at 13:52 comment added Konrad Rudolph @Antti I’m well aware of the impossibility of tokenising C++ code. But, contrary to what you’ve said, many modern syntax highlighters try to assign meaning to tokens without parsing. GitHub’s syntax highlighter and VS Code’s (parse-less mode), in particular, fundamentally have the same issue; they do a slightly better job but they still get it wrong (see second link).
Oct 8, 2020 at 11:42 comment added Antti Haapala @KonradRudolph most of those that do, also parse the source code and colour according to the AST not just tokens. In C++ especially it is impossible to get right without parsing the entire source code. int a(x) is a function declaration if x is a type, it is a variable declaration with a constructor call if x is an object, and you know this only by processing all the includes.
Oct 5, 2020 at 8:54 comment added Konrad Rudolph Actually I’ve submitted a new issue for this specific bug, since none of the existing issues directly address it: github.com/highlightjs/highlight.js/issues/2736 — As a further explanation, highlight.js does not try to be context free (and, contrary to your assertion, Antti, nor do many other widespread highlighters). In particular, it attempts to recognise declarations of functions and classes/structs, and highlight them separately. This improves readability, it’s just hard to get right. Currently it merely looks for the presence of a struct keyword, which is insufficient.
Oct 4, 2020 at 11:07 comment added Rob Grant Thanks; makes sense. I would definitely say that if SO are using this lib instead of writing their own highlighter, it's on them to add this support if they want their syntax highlighting to work.
Oct 2, 2020 at 10:16 comment added Konrad Rudolph @RobGrant Help wanted from the lib’s perspective. Of course SO would want this fixed, but I’m not seeing them devote any development resources towards highlight.js at the moment.
Oct 2, 2020 at 10:03 comment added Rob Grant @KonradRudolph Why would SO not want this fixed? Or do you mean it's help wanted from the lib's perspective?
Sep 30, 2020 at 10:38 comment added Konrad Rudolph This is an open issue: splitting C and C++ should happen (and C++ also needs to be drastically improved). As with pretty much all language-level improvements of the highlighter, this is “help wanted”, i.e. probably won’t happen without somebody submitting a pull request.
Sep 30, 2020 at 7:55 history edited Antti Haapala CC BY-SA 4.0
added 125 characters in body
Sep 29, 2020 at 19:53 history edited Antti Haapala CC BY-SA 4.0
deleted 2 characters in body
Sep 29, 2020 at 19:44 history edited Antti Haapala CC BY-SA 4.0
added 178 characters in body
Sep 29, 2020 at 19:22 history answered Antti Haapala CC BY-SA 4.0