Skip to content

Instantly share code, notes, and snippets.

@jcenters
Created April 23, 2014 05:05
Show Gist options
  • Save jcenters/11203287 to your computer and use it in GitHub Desktop.
Save jcenters/11203287 to your computer and use it in GitHub Desktop.
A Perl parser for the CriticMarkup language.
#!/usr/bin/perl
# Critic Markup Processor
# Based on CriticMarkup by Gabe Weatherhead and Erik Hess.
# http://criticmarkup.com/
# Strips CriticMarkup tags and performs the appropriate substitutions:
# Addition {++ ++} - Removes tags surrounding the Addition text.
# Deletion {-- --} - Deletes the tags and the text.
# Substitution {~~ ~> ~~} - Replaces the text with the substitution.
# Comment {>> <<} - Strips out the comment and the tag.
# Highlight {== ==} - Deletes the tags and the text.
# Serving Suggestions: Pipe text into CriticMarkup.pl
# from the command line or install as a BBEdit Text Filter.
# 2014 Josh Centers. http://joshcenters.com/
use strict;
use warnings;
use diagnostics;
my $text; # Our hero, the $text variable.
local $/; # Grab all the text.
$text = <>; # Assign STDIN to our hero.
print CriticMarkup($text);
sub CriticMarkup {
$text =~ s/(\{?)\+\+(\}?)//g; # Strip Addition tags.
$text =~ s/\{--(.*?)--\} ?//g; # Strip Deletions.
$text =~ s/(\{?)==(\}?)//g; # Strip Highlight tags.
$text =~ s/\{>>(.*?)<<\} ?//g; # Strip Comments.
$text =~ s/(\{~~.*?~>)//g; # Strip Substitution opening tags.
$text =~ s/(~~\})//g; # Strip Substitution closing tag.
return $text . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment