Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript syntax highlighter that plays nicely with Markdown

I've looked at a few Javascript programs to add syntax highlighting to code blocks on a page, but they all the ones I've found require setting an attribute on the code block to tell it what language is being used. I am generating the HTML with Markdown, so I have no way of setting these attributes, are there any that will do this automatically and will not need an attribute to be set?

The only way I can think of this working is with a shebang line;

#!/usr/bin/ruby
def foo(bar)
    bar
end

And it will know it's Ruby, and maybe even not display the shebang line (having a shebang for a one or two line fragment will get tiring).

I wont be needing it to do any very obscure languages, but it would be great if I could easily write new definitions.

Thanks.

like image 755
Jeffrey Aylesworth Avatar asked Feb 25 '23 13:02

Jeffrey Aylesworth


1 Answers

Google Prettifier should do the job. StackOverflow uses it, too (with the markup generated by Markdown). It determines the language automatically.

like image 169
jwueller Avatar answered Mar 24 '23 20:03

jwueller