Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use code block formatting in gmail (or any other email)?

Tags:

gmail

This question is not very technical, but I am trying to do something specific with formatting code for use in emails. I am trying to email a colleague several command line prompts like the one below:

C:\Users\DOOKIE\Documents\research>hg branches
default                      476:7556c41ee089

I would like to send it in a codeblock, with a grey background similar to the format above. Does anyone know how to do this in Gmail?

like image 344
modulitos Avatar asked Jun 17 '13 19:06

modulitos


2 Answers

I discovered a plug-in (at least for Google chrome) called Markdown that is a lightweight markup language used for formatting text. It is currently used for project communication on GitHub and BitBucket repositories. I am sure there are similar solutions out there, but a browser plug-in like Markdown seems like a good way to go.

Through the use of tags, I can quote code and scripts, like the one in the above question, into a desired format. Simply adding three backticks (```) before and after any code will create a code block.

https://markdown-here.com/

like image 168
modulitos Avatar answered Oct 13 '22 09:10

modulitos


A good option is to use VS Code. A simple Ctrl C and Ctrl V will grab the code along with highlighting and your editor theme (In my case dark). You'll get something like: Code sent via email with dark mode with highlighting

Another option is a Chrome extension called Markdown Here which supports GitHub flavored markdown. Using the extension, here is what I achieved by enclosing Python code with ```Python (some code)``` Code sent via email highlighted using Markdown Here.

I find the Vs code version more good looking though. Happy highlighting!

Ps: Usually to highlight code we enclose it in three backticks (```) and if you want the code highlighted in a certain language syntax you write the name of the language after the opening backticks then the code and finally the closing set. An example with Python would be opening backticks, the word 'Python', the code then closing backticks. You will end up with something like:

print is True
if print is True:
    print('sample python code')
else:
    pass

like image 45
Denis Kipkoech Biwott Avatar answered Oct 13 '22 08:10

Denis Kipkoech Biwott