Created
February 17, 2013 17:06
-
-
Save artagnon/4972301 to your computer and use it in GitHub Desktop.
A part of claytext.rb from artagnon/clayoven
This file contains 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
def process!(body) | |
htmlescape_rules = { | |
"&" => "&", | |
"\"" => """, | |
"'" => "'", | |
"<" => "<", | |
">" => ">" | |
}.freeze | |
paragraph_types = [:plain, :emailquote, :codeblock, :header, :footer] | |
paragraph_rules = { | |
Proc.new { |line| line.start_with? "> " } => lambda { |paragraph| | |
paragraph.type = :emailquote }, | |
Proc.new { |line| line.start_with? " " } => lambda { |paragraph| | |
paragraph.type = :codeblock }, | |
Proc.new { |line| /^\[\d+\]: / =~ line } => lambda { |paragraph| | |
paragraph.content.gsub!(%r{^(\[\d+\]:) (.*://(.*))}) { | |
"#{$1} <a href=\"#{$2}\">#{$3[0, 64]}#{%{...} if $3.length > 67}</a>" | |
} | |
paragraph.type = :footer | |
} | |
}.freeze | |
# First, htmlescape the body text | |
body.gsub!(/[&"'<>]/, htmlescape_rules) | |
# ... and it continues | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment