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.
Web Applications Stack Exchange is a question and answer site for power users of web applications. It only takes a minute to sign up.Sign up to join this community
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.org 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 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.
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.
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 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.
I tried Code Pretty recommended in here, it's OK. I wish it were open source so somebody could EASILY program in a hot-key to use like others said. Makes it very useful for the professional world, e.g., coding up how-to or wiki-like documents teaching others how to automate/code things.
I tried Code Blocks instead. I like it much more. Much easier to tell code apart from the document for training or writing your own notes when learning another new language.
Vim can output its syntax-highlighted buffer to an HTML file:
or this one is also nice:
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: