Gmail Syntax Highlighter

Viewed 29065

I sent my code to my friend over Gmail but as you guess, the code is not highlighted in Gmail. Is there solution to highlight code that is sent over Gmail?

10 Answers

Paste your code to an online (maybe offline) syntax highlighter, like http://tohtml.com/ . Then copy/paste it to gmail & send.

Unless you absolutely have to have the code in the email, I would just put your code on Pastebin and link to the code.

If you must put your code in the email, you could use a GreaseMonkey script such as this C++ highlighter, however that will not work for the person you're sending it to, only you. Another solution is to export your code as HTML (with coloring), and send it to the person as HTML. Try Visual Studio's CopySourceAsHtml plugin if you're using Visual Studio.

mac-oriented solution with Xcode:

I convert the code into an RTF file (using Xcode's qlmanage -p source_file -o Command described in here http://hints.macworld.com/article.php?story=20091104002118164).

Then open it in Word (NOT in textedit, when copying from textedit color gets lost), and copy and paste it from Word into gmail.

You can use MSFT's monaco editor via github.dev for this in two ways:

1. Just copy nice code

  1. Open https://github.dev
  2. Delete the contents of the markdown file, and write your code in syntax highlighting blocks (eg, "```ts").
  3. Copy code into gmail:

enter image description here

Personally, this is exactly what I was looking for.

2. Copy full markdown

  1. Write your whole email as markdown in the README editor.
  2. Press the "[Preview] README.md" tab.
  3. Copy/paste the result into gmail:

enter image description here

It is still nicely editable within gmail (though of course it won't re-highlight your syntax if you edit code).

The syntax highlighting is different (and in my opinion, uglier) with this option. The markdown preview engine is also a little wonky (definitely not the same as Github's); see the source for the above screenshot for an example (note the need to over-indent the inner numbered list).

Note that when you close & reopen the tab, the last contents you had will still be there. IMO this is a tremendous advantage, but if you are writing something private, you should delete the contents before closing the github.dev tab.

Related