-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prism vs Highlight.js: Why choose one over the other? #3625
Comments
I'll start:
|
@RunDevelopment How would you feel about some sort of cross-posting of this? |
This is pure speculation, but I have the feeling that Prism's popularity is tied closely to that of its author.
As a contributor to both projects, I wanted to share my opinion on this. For obvious reasons, I prefer reading (and writing!) grammar definitions as used by Highlight.js. I would love to see some numbers, on how much optimized RegEx patterns contribute to the performance of Prism. If there's a significant gain, it makes sense, but developer experience is an important factor as well. Personally, I've been using |
I just did :) It might be good to more clearly signpost this as a survey where we are collection feedback from the community. |
Sorry, that's my fault. I did request manually optimized keyword lists in the past, and that was honestly stupid. They were not only hard to read, write, and maintain, they were also slower than many "unoptimized" regexes. Turns out, browsers optimize character runs, so breaking up words too much can make regexes slower. Optimizing regexes based on tries sounds good in theory, but unfortunately rarely helps in practice. The old saying "premature optimization is the root of all evil" rang true once again. So I've changed course for a few years now and focus on readable regexes instead. Most of my usual nits and critiques when reviewing regexes were even automated by making a linter. I know this isn't a Q&A, but I still wanted to respond to it, because it was directly my fault. |
For me, the number one reason to use Highlight.js over anything else is the automatic language detection. I maintain a PHP library that's mostly used in forum software such as phpBB and Flarum. In my experience, most users don't fill in name of the programming language when posting code blocks. Without auto-detection or some kind of default, language-agnostic rules, there wouldn't be any highlighting. |
I came to hightlight.js because I use Aciidoc-revealjs to create my slide decks and the has the best support for hightlight.js. I never worked with prism and only contributed some new keywords to hightlight, but I am think I am better with the "simple" approach taken by hightlight ;-) |
This comment was marked as off-topic.
This comment was marked as off-topic.
dose Prism have all these themes? |
I think a major weakness of both syntax highlighters is they're based on regular expressions. Most if not all of the languages they highlight are not regular languages. They run into issues with things such as nesting. A syntax highlighter having proper context-free parsers would be a major reason to prefer one over all others. An earley parser with grammar data for all supported languages, for example. |
I am testing out react-syntax-highlighter which offers both highlight.js and prism and for my use case highlight.js is much faster. I am basically trying to have editable code with live syntax highlighting like how its done on discord. Prisma has better jsx/tsx support but its not worth it for the difference in speed. highlight.js does seem to support jsx/tsx a fair amount but a small thing that messes it up is something like this import { Comp_ } from "@component";
import { cn } from "../../Utils/cn";
import { useDarkMode } from "usehooks-ts";
const Comp = <T,/*<- this trailing comma as well as this comment*/>({className, ...props}: Comp_.Props<T>) => {
return (
<Comp_ {...props} classname={cn("w-full", className)} />
);
}
export {DatePicker}; |
This comment was marked as outdated.
This comment was marked as outdated.
I find this last comment a bit confusing/misleading on several points... so I'm hiding it. Neither library uses a simple lexer/tokenizer (that walks the code one character at a time).
|
Thanks for the information. From the https://highlightjs.org/, I cannot find any information mentioning the plugin part. The discussion you mentioned seems to be lengthy. Any easy way to make highlights to the operators and punctuations etc like PrismJS? |
I liked highlightJS but unfortunately didn't end up fitting our needs for the various reasons:
|
Prisme does not support language autodetection PrismJS/prism#1313 thank you highlightjs for your great work. |
I think we have a few good hooks, but I'd be open to adding more if they were well thought out. Open to suggestions. |
FYI: It looks like Prism isn't being maintained anymore unfortunately. The last activity was > 2 years ago (Aug 2022). So, for anyone who's starting fresh and choosing a (new) highlighter, that may be an important factor worth considering. Update: There was progress in a |
@joshgoebel sorry for the late reply. It been a while now, totally forgot what troubles i was running into with plugins. If I have spare moment in the next couple of weeks, ill try it out again and write something up for you 🙌🏽 |
Related: #3619 #3621 #3623
In trying to figure out the direction of the project moving forward, where we go, how we should or shouldn't integrate with other parsers (at the 1st party level), it'd be helpful to know WHY people prefer Highlight.js to Prism - or how they think about the differences. No detail is too large or too small. Or if you evaluated other highlighting solutions (than just these two), those thoughts would be welcome here also - provided you have a few points of comparison.
The parsing engines are of course very different. But I've never really thought about which is "better" in an absolute sense... I've just always assumed that a mono-culture is bad - and that it's good we have two great choices for highlighting on the client-side - and that people obviously have reasons for preferring one over the other.
Suddenly I'm much more curious about the WHY, and what those reasons are. Anyone care to share?
Lets keep this civil and respectful... it's ok to share perceived negatives, buts lets about things like "Highlight.js sucks because" or vise versa, etc...
The text was updated successfully, but these errors were encountered: