Permalink
Browse files

handling odd characters in code formatting

  • Loading branch information...
1 parent 140d117 commit f477de0f14d2bf8e77af55a2eca73511fab44915 @ryanb committed Aug 9, 2011
Showing with 4 additions and 5 deletions.
  1. +3 −5 lib/code_formatter.rb
  2. +1 −0 spec/lib/code_formatter_spec.rb
View
8 lib/code_formatter.rb
@@ -29,16 +29,14 @@ def to_html
end
def language(path)
- case path
+ case path.to_s.strip
when /\.yml$/ then "yaml"
when /\.js$/ then "java_script"
when /\.scss$/ then "css"
when /\.erb$/, /\.html$/ then "rhtml"
when /\.rb$/, /\.rake$/, /\.gemspec/, /file$/, /console$/, "rails" then "ruby"
- when /\./ then path[/\.([^.]+?)$/, 1].strip
- when "" then "text"
- when nil then "text"
- else path.strip
+ when /([a-z0-9]+)$/i then $1
+ else "text"
end
end
View
1 spec/lib/code_formatter_spec.rb
@@ -24,6 +24,7 @@ def format(text)
formatter.language("foo ").should eq("foo")
formatter.language("").should eq("text")
formatter.language(nil).should eq("text")
+ formatter.language("0```").should eq("text")
end
it "converts to markdown" do

0 comments on commit f477de0

Please sign in to comment.