Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic syntax highlighter

I'm looking for a good all rounded syntax highlighter written in JavaScript that will auto detect the language used and apply proper syntax highlighting.

I've found a myriad of them from a simple Google search but they all have to have some sort of formatted class on the <pre> element like <pre class="highlight-php">.

I noticed StackOverflow's syntax highlighting manages to do it automatically from within pre blocks, anyone know what library they're using?

Thanks!

like image 979
James Dawson Avatar asked Jan 24 '13 14:01

James Dawson


People also ask

How do I turn on syntax highlighting?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

How do you highlight syntax in HTML?

When creating or editing posts, syntax highlighting is assigned to the preview based on question's tags as soon as you stop typing for 5 seconds. Stack Exchange does not have its own syntax highlighting engine. It uses highlight. js, and may not necessarily be using the latest release of that library.

How does a syntax highlighter work?

Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords like if or for in JavaScript differently than strings and comments and variable names.

How do you highlight codes?

Highlight using the HTML5 <mark> tag If you are working on an HTML5 page, the <mark> tag can quickly highlight text. Below is an example of the how to use the mark tag and its result. If your browser supports the <mark> tag, "highlighted text" should have a yellow background.


1 Answers

They are using google prettify. There are other options, such as highlight.js

like image 72
gameweld Avatar answered Jan 01 '23 12:01

gameweld