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.
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:
insert_time = n * n
merge_time = 8 * n * math.log(n, 2)
print("Insertion Sort is faster than Merge Sort for n = %d: " %n, end="")
print(insert_time < merge_time)
for n in range(1, 100):
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.