Need to paste a code snippet into Microsoft Word or WordPress?

Pasting Code into Microsoft Word

I’ve been working on an assignment for a Data Structures and Algorithms class, and wrote a little piece of Python code to compare two different sort functions. I have to submit the homework as a single Word document. Since I can’t zip up the script along with the .doc and submit it that way, I started looking for an easy way to copy formatted code from Atom to paste into a Word 2013 document. I Googled my way into some answers involving using a plugin to copy the code as RTF and then paste it into a new object in the .doc, but I didn’t have much success with that method.

After Googling some more I stumbled on this online syntax highlighting converter that allows you to post code from your editor, select a language, and you end up with a snippet you can copy and paste directly into your Word doc. It’s not the most elaborate highlighting, but it does the trick if you just want to put some code into a Word document and have it look like code. The site says it only works in IE, but it worked in Chrome for me. It uses SyntaxHighlighter, an open-source client side syntax highlighter written in JavaScript.

If anyone has a better solution for copy-pasting code from Atom into Word, let me know!

Pasting Code into WordPress

I had researched WordPress plugins for code highlighting before, but somehow missed the most obvious solutions. The above-mentioned SyntaxHighlighter is apparently used all over the Internet for just this purpose. WordPress.com hosted sites can use this implementation of SyntaxHighlighter. If you manage your own hosted WordPress site, there are several plugins that you can use, but I chose Crayon Syntax Highlighter. I picked this one because it seems to be well-updated, has a large install base, and lots of good reviews. I have to say my first impressions are very positive. There are a ton of features I may never use, but the basic configuration and editing is really easy. Here is an example of what it can do:

Not only do you get some nicely syntax highlighted code in the theme of your choice, you get a little toolbar with a title for the snippet, some tools for viewing and copying the code, as well as the language the code is written in. Everything is incredibly customizable through the plugin settings, which include a theme editor for creating or modifying themes.

If you’ve used one of the other WordPress syntax highlighting plugins, let me know what you think.

Chris Bryant / August 31, 2015 / blogging, computer science, education, javascript, programming, python, writing