Live data from Hacker News

Highlight.js – Syntax highlighting for the Web

highlightjs.org

51–60 of 72 posts

Re: Highlight.js – Syntax highlighting for the Web

#51

I've tried Highlight.js before and I was never really a big fan of it. It seemed too heavy last time I tried it. I've been using rainbow.js for a year or two now. http://craig.is/making/rainbows/

Rainbow doesn't seem to have line numbers. Is there another module available that allows integration of lone numbers?

Re: Highlight.js – Syntax highlighting for the Web

#53

This is my favorite syntax highlighting JS library, by far. The approach this library takes to building the highlighted DOM tree is very clever. It represents the original DOM and the highlighted code output as separate streams of tag open / close events and then merges them together. This allows the highlighter to maintain the pre-existing DOM structure of the highlighted code! The language auto-detection and sub-la…

Sounds exactly like what I implemented 4 years ago.

Here is where you extract the existing HTML tags: https://github.com/ioquatix/jquery-syntax/blob/97e38d08924d7...

When you brush the code (extract highlighing information) you provide the set of initial matches which are converted into a tree: https://github.com/ioquatix/jquery-syntax/blob/97e38d08924d7... - there is no merge step, they are merged in place in the tree which is then used to generate DOM (or whatever you like really) output.

I never implemented language auto-detection but I'm sure I've seen that implemented before prism before, perhaps Google's Prettify might have been one of the first to do it. It basically highlights using all available brushes and looks at which one matches the most tokens - not sure if this is how it is currently implemented though. My feeling is that you usually know what language you are highlighting, the auto-highlighter wouldn't always get it right, and the cost of loading all brushes/languages is pretty high (imagine for example you have 100 different languages supported, you'd have to do all of them)..

The sub-language handling in jQuery.Syntax is as precise as possible: https://github.com/ioquatix/jquery-syntax/blob/97e38d08924d7...

Basically, if you match some sub-portion of the code, you then highlight that using a different brush. Sometimes it's almost impossible to know though (e.g. diffs which may be incomplete).

Re: Highlight.js – Syntax highlighting for the Web

#54

Anyone know of one of these that supports some kind of callouts? Basically I want to be able to annotate groups of 1 or more lines, something like this, probably using some kind of inline comment http://reference.bitreactive.com/reference/images/tutorial/s...

jQuery.Syntax does support preserving the original DOM elements, so you could do this.

Re: Highlight.js – Syntax highlighting for the Web

#55

We use highlight.js at Resonant Core for our blog posts. After reading the comments here, I'm considering forking it to support line numbers :)

jQuery.Syntax supports line numbers and is generally pretty awesome *

* I'm the author so of course I'd say that :)

Re: Highlight.js – Syntax highlighting for the Web

#56

At one point I got really into the idea of ASTs for languages. I've used pygments, the python syntax highlighter, with the intention of parsing the meaning of code. These syntax highlighters are great but I think that underlie the lack of a defined and accessible AST parse definition for most languages. Highlight.js and others kind of just rely regexes-- https://github.com/isagalaev/highlight.js/blob/master/src/la...…

I believe CodeMirror does something like this. It uses restartable parsers (or it used to) to make parsing fast while editing.

I experimented editing code using jQuery.Syntax. I used the match tree it generated to figure out where to restart parsing and it was pretty fast, it would only re-evaluate the current line in most cases.

Re: Highlight.js – Syntax highlighting for the Web

#57
What's the recommended way of using something like this or prism.js to highlight a simple textarea containing code?

I'm not talking a full-on programming editor, that's a much larger scope. Rather, I have an admin tool with a that allows entering short code snippets, and it would be handy to see highlighting as you type. Even at this low level of complexity, is it simpler to just embed something like Ace, or is there an easy way to use a highlighting library?

Re: Highlight.js – Syntax highlighting for the Web

#58
post #57

What's the recommended way of using something like this or prism.js to highlight a simple textarea containing code? I'm not talking a full-on programming editor, that's a much larger scope. Rather, I have an admin tool with a that allows entering short code snippets, and it would be handy to see highlighting as you type. Even at this low level of complexity, is it simpler to just embed something like Ace, or is there…

Have you looked at CodeMirror? It might be a better fit for highlighting editable text.

Re: Highlight.js – Syntax highlighting for the Web

#59

Earlier quoted context omitted.

It would be really helpful when presenting at Events. A lot of events record the presenters screen and the presenter but expect the presenter to stand in one spot so they don't need a cameraman. So, it does not work very well to point at a screen when presenting.

It should be a trivial patch. I'll see about getting it done tonight.

Famous last words ;)

Re: Highlight.js – Syntax highlighting for the Web

#60
post #50
post #47

Earlier quoted context omitted.

Why wouldn't I want that? If I am copying and pasting code from a website, it usually goes to my editor and I don't want to have to delete the line numbers from it.

You don't want the line numbers.

Oh if that's what he meant then I read it the wrong way.
Post reply on HN