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?

4

3 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.

2

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 

I have used a google drive plugin Code Blocks . Only works in Google Drive docs but similar to the VS code answer you can copy and paste the code block formatting to Gmail.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy