Gmail Syntax Highlighter
Asked Answered
A

10

46

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?

Activist answered 20/7, 2009 at 6:39 Comment(0)
Q
23

consider using gist.github.com

some benefits:

  • you can copy and paste the syntax highlighted code into gmail
    • (its not always perfect but gets the job done, see screenshot below) enter image description here
  • snippet(s) can be shared with a hyperlink (also bookmarkable)
  • you don't need an account to share code snippets
    • code can still be kept private and is only shared with those have the secret link
  • you can specify the language or snippet type, or even multiple snippets on a single page
  • you can also access historical changes of the snippet making it easy to track revisions over time
Quad answered 12/3, 2015 at 15:27 Comment(3)
Do not use this extension as it is removed from ChromeWebStore for a good reason. The reason it got banned is explained by @DrenaiBoyles
I think Gist does not support on 2021, when I paste to Gmail, no syntax highlighted. I prefer write via markdown, then paste to Gmail, e.g. I write in Typora, it works for me.Trackandfield
In 2022, still seeing no syntax highlighting when copying from Gist to Gmail. However, using github.dev did work wonderfully, and looks the ~same.Vaughn
B
42

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

Bertie answered 20/7, 2009 at 6:44 Comment(5)
This is good for me but I wish there should be a gmail plugin in gmail labs. Thanks Ahmet...Activist
It somehow seems to make the font size very smallLegate
Somehow it messes up highlighting for quotation marks in python.Brahmin
@EricWalker same for SQL tooYasmineyasu
That doesn't seem to work well for me now. Using github.dev was the best I could find right now.Vaughn
Q
23

consider using gist.github.com

some benefits:

  • you can copy and paste the syntax highlighted code into gmail
    • (its not always perfect but gets the job done, see screenshot below) enter image description here
  • snippet(s) can be shared with a hyperlink (also bookmarkable)
  • you don't need an account to share code snippets
    • code can still be kept private and is only shared with those have the secret link
  • you can specify the language or snippet type, or even multiple snippets on a single page
  • you can also access historical changes of the snippet making it easy to track revisions over time
Quad answered 12/3, 2015 at 15:27 Comment(3)
Do not use this extension as it is removed from ChromeWebStore for a good reason. The reason it got banned is explained by @DrenaiBoyles
I think Gist does not support on 2021, when I paste to Gmail, no syntax highlighted. I prefer write via markdown, then paste to Gmail, e.g. I write in Typora, it works for me.Trackandfield
In 2022, still seeing no syntax highlighting when copying from Gist to Gmail. However, using github.dev did work wonderfully, and looks the ~same.Vaughn
P
9

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.

Parallax answered 20/7, 2009 at 6:45 Comment(1)
I prefer to use internal application not external link. So generating highlighted html code for sourcecode is the best way.Activist
B
9

If your language is not available at http://tohtml.com but you use GitHub you can also paste into a (private) gist there - http://gist.github.com/ - then copy&paste back to gmail.

Beatification answered 3/6, 2010 at 17:36 Comment(0)
T
4

Use markdown-here. You can write markdown in mails with the extension. The extension format mail content to html and highlight the code. I think this is an excellent extension.

An example

Tortola answered 17/2, 2014 at 9:5 Comment(1)
Note this has not been maintained for many years now. It also does not support converting rendering, editing, and then rendering again, which was a dealbreaker for me.Vaughn
L
1

If I have to send a snippet of Java code from Eclipse, I copy paste the code into Microsoft Word and then from Word into Gmail. That preserves the HTML formatting. If you use an email program such as Outlook, just copying and pasting from Eclipse into Outlook works.

Legate answered 3/3, 2011 at 17:35 Comment(0)
V
1

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.

Vaughn answered 20/8, 2022 at 8:36 Comment(0)
H
0

Try http://jsbin.com/. Easy to write html/JavaScript and test. Just copy paste the code from jsbin to gmail.

Harbour answered 4/11, 2010 at 4:23 Comment(0)
H
0

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.

Homager answered 7/3, 2012 at 22:0 Comment(0)
L
0

For those of you looking to copy/paste from xCode to email, I simply copy from xCode and paste into Mac's default email client ("Mail"). It keeps all the formatting with colors.

Lemnos answered 11/1, 2015 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.