Created
April 23, 2014 05:05
-
-
Save jcenters/11203287 to your computer and use it in GitHub Desktop.
A Perl parser for the CriticMarkup language.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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