Adding syntax highlighting to code snippets in Evernote

You can't get syntax highlighting in Evernote directly, but what you can do is use an online syntax highlighting service and copy the highlighted content straight from the page.

First, I went to http://tohtml.com/auto/ and pasted in some code:

<?php
  for ($i=0; $i<4; $i++) {
    echo 'This is a test of syntax highlighting in Evernote using Pastebin';
  }
?>

Then, I copied the resulting code from the output, which you see here, and paste it into an Evernote note. 

You could also use the Evernote Firefox plugin to create a note straight-up, but it's a pain trying to undo the CSS styling to get some plain text in before your code, so I would create a new note, add a couple of blank lines to the beginning, and paste in the code after that.

The result is what you see below. This works because Evernote stores HTML as HTML, and if there's embedded style tags, those will get copied over too. I first tried this experiment with Pastebin, but it didn't work because the styling is not inline.

<?php
  for ($i=0; $i<4; $i++) {
    echo 'This is a test of syntax highlighting in Evernote using Pastebin';
  }
?> 
Online syntax highlighting for &quot;PHP&quot; HTML code: 'pre style colon #000000 backgroundi/lf tttt '&gt;&lt;epan stylo- color &lt;npan style- colon #000000; background ic9 &gt;t#xa0; &lt;apan stylo-' colon #000000; sa EOLIAN background:*! foS; &lt;apan style- color bacisiour.d I&lt;«8; THUMB /pro- no,..- reoJOUVV Nfl coupon oay. Ill MM eoing ftr»it 90% of» Gt-JW COME so Preview &lt;?php lor (Si-Oi tl&lt;1&gt; til-) echo 'This ia TOOT of SYNTAX highlighting In Evornoto using Paatobin'; Source code or (Sl-0; Si&lt;*; Si&gt;*) echo 'Thia ia tost of syntax highlighting in jornoto using Past* Style Hi Type: RECENT Type: PEP 00000 xapan ODE OR SHAN FOR colon #00 0000 j background: MUDD WITAN is IN style&quot; color [#000000; NAIROBI COlori#a65700j SCHOOL DAY in |*nH (Si


Comments

Good call, I was looking at Code Collector, Snippet, and a couple of other apps, but I used Evernote all the time, just didn't like the non-highlighted code. Awesome!

Thanks Chris!

Hey Pat, a belated "your welcome", enjoy!

Thanks for this, I was searching for something similar. As an alternative, I found the following: Highlight (http://www.andre-simon.de/). It supports more languages (160), some of which I use and tohtml does not support, has more css themes (80) and it is a native app (all OSs I think). I noticed that it also has an api and a cli, so maybe someday I will get some time and either do a plug-in into Evernote or into Highlight that would connect the two. Just an FYI, if you use it, don't use the copy preview to clipboard, but hightlight the preview and copy it or it won't work into Evernote.

I'm working on a code snippet tool that integrates with Evernote called Sniptastic! (http://www.sniptastic.com/). It's still in
the early stages, but development is going very quickly. It has syntax
highlighting and a plugin for Visual Studio.

How did you manage to get proper indentation and line breaks?
I can get the colors just fine, but all other formatting is lost.