Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
APA to MLA commas

Convert from APA style commas to MLA

This is for all your writer friends: for the MLA or APA purist, why not introduce a little excitement to their day with a belated April fools prank?

Installation

Download the comma script and chmod +x comma to make it executable.

Usage

./comma help

You can pass input via STDIN:

echo "Bacon, eggs and toast." | ./comma

Or as a filename in the first argument. For example, if your cd'ed to the same directory:

./comma my-text-file.txt

Throw the comma command into your build scripts or any command your victim normally runs.

Watch mass chaos ensue, but you get to clean up the mess!

#!/usr/bin/env ruby
usage = <<EOF
#====================================================
#--- APA => MLA -------------------------------------
#--- Convert APA commas to MLA, and vice versa ------
#--- Pass in STDIN, or a file as the argument -------
#====================================================
EOF
sample = <<EOF
Once upon a time: I had bacon, eggs and toast. Then I was sad, because there was no bacon.
Or toast, or eggs.
But then, behold! Bacon, eggs, and toast came hurrying to my plate to make me breakfast.
EOF
if ARGV[0] == "help"
puts usage
puts
puts "Here's an example (run `echo | ./comma`):"
puts "========================================="
puts sample
exit
end
apa = /((?:[^,.?!;:\n\r]+,)+(?:[^,.?!;:\n\r]+)) and ([^,.?!;:\n\r]+)/
mla = /((?:[^,.?!;:\n\r]+,)+(?:[^,.?!;:\n\r]+)), and ([^,.?!;:\n\r]+)/
string = ARGF.read
string = sample if string.chomp == ""
# Pick your poison
mla_ed = string.gsub(apa, '\1, an oxford comma, and \2')
# apa_ed = string.gsub(mla, '\1, no oxford comma and \2')
puts mla_ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment