Is there way to switch on syntax highlighting in Google Docs?
Personally I use it for editing and collaborating on C++ files, but PHP or SQL syntax highlighting also would be interesting.
Is there way to switch on syntax highlighting in Google Docs?
Personally I use it for editing and collaborating on C++ files, but PHP or SQL syntax highlighting also would be interesting.
With the new Add-Ons for Google Drive, you can get code highlighting with the Code Blocks add-on.
After installing the add-on, you can access it by selecting the code you want to format, go to _Add-ons → Code Blocks → Start:
This pops up a sidebar where you can select the programming language and a theme:
After clicking Format, the result looks like this:
I've found Codepad which allows to share code snippets. It supports syntax highlighting and even compilation of code. And it supports wide range of programming languages — C, C++, D, Haskell, Lua, OCaml, PHP, Perl, Python, Ruby, Scheme, Tcl. And one more great feature — it does not require to login.
You can add-on Code Block for Google Docs.
1*- Google Docs --> Add-ons Tab --> 2*- Get Add-ons ... --> Search For: 'Code Blocks'
3*- Then you go to Add-ons --> Code Block --> Start
4*- Select Theme(50+)
You can make use of the the question or answer fields on Stack Exchange sites to help out.
Google Docs seems to reset the font for some reason, but preserves the syntax highlighting. Good for including code snippets into documentation.
Just to be clear for rookies like me,
No, there is no code highlighting natively in Google Docs.
There are add ons that can do code highlighting.
Code Pretty is mentioned above and has adequate reviews.
Code Block is also mentioned and has good reviews.
If you don't want to install add ons it gets harder. http://markup.su/highlighter/ is mentioned above as being good, and it does a pretty good job. You just have to copy and paste the code each time there is a change.
If you want code formatting just for documentation purposes, these solutions will work.
If you want the real time collaboration, there are much better solutions for code than Google Docs.
Check out solutions like https://codeshare.io/
I've found out that copying pastes from Pastebin works perfectly, and as an added bonus it adds line numbers that are recognized by Google Docs as numbered list.
You go to Pastebin, create an unlisted paste (if you don't want anyone else to see it), select syntax highlighting from large number of available languages and syntaxes, hit Submit, then select and copy highlighted text into your Google Document.
Google Docs launched "Code blocks" on December 14, 2022.
It is available to some accounts (depending on the pricing plan). It is not available to users with personal Google Accounts.
To format and display code in a Doc, select Insert > Building blocks > Code blocks > choose your programming language or search @ > Code blocks > choose your programming language.
Google's announcement: Easily format and display code in Google Docs
I faced this problem too, and I didn't want to add any extension to my Google Docs account. I found http://markup.su/highlighter/ , an online code syntax highlighter, you just past your code and can chose between different styles.
I personally use the style "Dawn", then past the output in a tab in the doc, remove the borders and set a background to this tab. The result is good.
You can paste it into VSCode and copy from there, then paste into GDocs, the formatting will be preserved with syntax highlighting and monospace font.
Vim can output its syntax-highlighted buffer to an HTML file:
http://vim.wikia.com/wiki/Pasting_code_with_syntax_coloring_in_emails
or this one is also nice:
https://superuser.com/questions/565050/export-file-syntax-highlighting-to-html-using-vim
This file can be opened in your browser, from where you can copy and paste the text over to Google Docs/Drive.
For something simple try rextester. It allows to collaborate real-time on code snippets written in many languages. Go to 'run code', choose your language and then hit 'Live cooperation' button.
This is a bit of a roundabout way to get Vim (or any other tool that can save a file in the form of HTML) syntax highlighting in a Google Doc:
I just copy and pasted my code from VS Code into my Google Doc, and it appears beautifully formatted, even with my theme colors.
I just had to change the font and line spacing in the document.
Details:
Running on Mac OS, in March 2021, VS Code version: Version: 1.53.2.