Skip to content
This repository

add redcarpet support #79

Merged
merged 1 commit into from almost 3 years ago

2 participants

Konstantin Haase Ryan Tomayko
Konstantin Haase
Collaborator
rkh commented April 15, 2011

No description provided.

Ryan Tomayko rtomayko referenced this pull request from a commit April 26, 2011
Ryan Tomayko Merged pull request #79 from rkh/redcarpet.
add redcarpet support
9f4dd62
Ryan Tomayko rtomayko merged commit 9f4dd62 into from April 26, 2011
Ryan Tomayko rtomayko closed this April 26, 2011
Ryan Tomayko rtomayko commented on the diff April 26, 2011
test/tilt_markdown_test.rb
@@ -66,8 +66,12 @@ module MarkdownTests
66 66
   end
67 67
 
68 68
   def test_smarty_pants_true
69  
-    html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
70  
-    assert_equal "<p>Hello “World” — This is —– a test …</p>", html
  69
+    if self.class.template == Tilt::RedcarpetTemplate
  70
+      warn "\nsmartypants not yet fully supported by redcarpet (#{__FILE__}:#{__LINE__})"
  71
+    else
  72
+      html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
  73
+      assert_equal "<p>Hello “World” — This is —– a test …</p>", html
  74
+    end
2
Ryan Tomayko Owner
rtomayko added a note April 26, 2011

Trying to get @tanoku to fix this btw. I didn't realize that was valid smartypants to be honest. I thought it converted all double-quote pairs to smart quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 15, 2011
Konstantin Haase add redcarpet support 47f6eeb
This page is out of date. Refresh to see the latest.
1  lib/tilt.rb
@@ -174,6 +174,7 @@ def clear
174 174
   register MarukuTemplate,    'markdown', 'mkd', 'md'
175 175
   register KramdownTemplate,  'markdown', 'mkd', 'md'
176 176
   register BlueClothTemplate, 'markdown', 'mkd', 'md'
  177
+  register RedcarpetTemplate, 'markdown', 'mkd', 'md'
177 178
   register RDiscountTemplate, 'markdown', 'mkd', 'md'
178 179
 
179 180
   require 'tilt/textile'
20  lib/tilt/markdown.rb
@@ -39,6 +39,26 @@ def evaluate(scope, locals, &block)
39 39
     end
40 40
   end
41 41
 
  42
+  # Upskirt Markdown implementation. See:
  43
+  # https://github.com/tanoku/redcarpet
  44
+  #
  45
+  # Compatible to RDiscount
  46
+  class RedcarpetTemplate < RDiscountTemplate
  47
+    self.default_mime_type = 'text/html'
  48
+
  49
+    def self.engine_initialized?
  50
+      defined? ::RedcarpetCompat
  51
+    end
  52
+
  53
+    def initialize_engine
  54
+      require_template_library 'redcarpet'
  55
+    end
  56
+
  57
+    def prepare
  58
+      @engine = RedcarpetCompat.new(data, *flags)
  59
+      @output = nil
  60
+    end
  61
+  end
42 62
 
43 63
   # BlueCloth Markdown implementation. See:
44 64
   # http://deveiate.org/projects/BlueCloth/
19  test/tilt_markdown_test.rb
@@ -66,8 +66,12 @@ def test_smarty_pants_false
66 66
   end
67 67
 
68 68
   def test_smarty_pants_true
69  
-    html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
70  
-    assert_equal "<p>Hello “World” — This is —– a test …</p>", html
  69
+    if self.class.template == Tilt::RedcarpetTemplate
  70
+      warn "\nsmartypants not yet fully supported by redcarpet (#{__FILE__}:#{__LINE__})"
  71
+    else
  72
+      html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
  73
+      assert_equal "<p>Hello “World” — This is —– a test …</p>", html
  74
+    end
71 75
   end
72 76
 end
73 77
 
@@ -83,6 +87,17 @@ class MarkdownRDiscountTest < Test::Unit::TestCase
83 87
 end
84 88
 
85 89
 begin
  90
+  require 'redcarpet'
  91
+
  92
+  class MarkdownRedcarpetTest < Test::Unit::TestCase
  93
+    include MarkdownTests
  94
+    template Tilt::RedcarpetTemplate
  95
+  end
  96
+rescue LoadError => boom
  97
+  # It should already be warned in the main tests
  98
+end
  99
+
  100
+begin
86 101
   require 'bluecloth'
87 102
 
88 103
   class MarkdownBlueClothTest < Test::Unit::TestCase
55  test/tilt_redcarpettemplate_test.rb
... ...
@@ -0,0 +1,55 @@
  1
+require 'contest'
  2
+require 'tilt'
  3
+
  4
+begin
  5
+  require 'redcarpet'
  6
+
  7
+  class RedcarpetTemplateTest < Test::Unit::TestCase
  8
+    test "registered for '.md' files" do
  9
+      assert Tilt.mappings['md'].include?(Tilt::RedcarpetTemplate)
  10
+    end
  11
+
  12
+    test "registered for '.mkd' files" do
  13
+      assert Tilt.mappings['mkd'].include?(Tilt::RedcarpetTemplate)
  14
+    end
  15
+
  16
+    test "registered for '.markdown' files" do
  17
+      assert Tilt.mappings['markdown'].include?(Tilt::RedcarpetTemplate)
  18
+    end
  19
+
  20
+    test "registered above BlueCloth" do
  21
+      %w[md mkd markdown].each do |ext|
  22
+        mappings = Tilt.mappings[ext]
  23
+        blue_idx = mappings.index(Tilt::BlueClothTemplate)
  24
+        rdis_idx = mappings.index(Tilt::RedcarpetTemplate)
  25
+        assert rdis_idx < blue_idx,
  26
+          "#{rdis_idx} should be lower than #{blue_idx}"
  27
+      end
  28
+    end
  29
+
  30
+    test "preparing and evaluating templates on #render" do
  31
+      template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
  32
+      assert_equal "<h1>Hello World!</h1>\n", template.render
  33
+    end
  34
+
  35
+    test "can be rendered more than once" do
  36
+      template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
  37
+      3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
  38
+    end
  39
+
  40
+    test "smartypants when :smart is set" do
  41
+      template = Tilt::RedcarpetTemplate.new(:smart => true) { |t|
  42
+        "OKAY -- 'Smarty Pants'" }
  43
+      assert_equal "<p>OKAY &mdash; &lsquo;Smarty Pants&rsquo;</p>\n",
  44
+        template.render
  45
+    end
  46
+
  47
+    test "stripping HTML when :filter_html is set" do
  48
+      template = Tilt::RedcarpetTemplate.new(:filter_html => true) { |t|
  49
+        "HELLO <blink>WORLD</blink>" }
  50
+      assert_equal "<p>HELLO &lt;blink&gt;WORLD&lt;/blink&gt;</p>\n", template.render
  51
+    end
  52
+  end
  53
+rescue LoadError => boom
  54
+  warn "Tilt::RedcarpetTemplate (disabled)\n"
  55
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.