Skip to content
This repository
Browse code

handling odd characters in code formatting

  • Loading branch information...
commit f477de0f14d2bf8e77af55a2eca73511fab44915 1 parent 140d117
Ryan Bates authored August 09, 2011
8  lib/code_formatter.rb
@@ -29,16 +29,14 @@ def to_html
29 29
   end
30 30
 
31 31
   def language(path)
32  
-    case path
  32
+    case path.to_s.strip
33 33
     when /\.yml$/ then "yaml"
34 34
     when /\.js$/ then "java_script"
35 35
     when /\.scss$/ then "css"
36 36
     when /\.erb$/, /\.html$/ then "rhtml"
37 37
     when /\.rb$/, /\.rake$/, /\.gemspec/, /file$/, /console$/, "rails" then "ruby"
38  
-    when /\./ then path[/\.([^.]+?)$/, 1].strip
39  
-    when "" then "text"
40  
-    when nil then "text"
41  
-    else path.strip
  38
+    when /([a-z0-9]+)$/i then $1
  39
+    else "text"
42 40
     end
43 41
   end
44 42
 
1  spec/lib/code_formatter_spec.rb
@@ -24,6 +24,7 @@ def format(text)
24 24
     formatter.language("foo ").should eq("foo")
25 25
     formatter.language("").should eq("text")
26 26
     formatter.language(nil).should eq("text")
  27
+    formatter.language("0```").should eq("text")
27 28
   end
28 29
 
29 30
   it "converts to markdown" do

0 notes on commit f477de0

Please sign in to comment.
Something went wrong with that request. Please try again.