Sha256: 3e5e860c6e786b7baf021491a588f24be7ce3081a4418234c89515437fa622f7

Contents?: true

Size: 1.49 KB

Versions: 17

Compression:

Stored size: 1.49 KB

Contents

# coding: UTF-8
require 'test_helper'

class CustomRenderTest < Redcarpet::TestCase
  class SimpleRender < Redcarpet::Render::HTML
    def emphasis(text)
      if @options[:no_intra_emphasis]
        return %(<em class="no_intra_emphasis">#{text}</em>)
      end

      %(<em class="cool">#{text}</em>)
    end

    def header(text, level)
      "My little poney" if @options[:with_toc_data]
    end
  end

  def test_simple_overload
    md = Redcarpet::Markdown.new(SimpleRender)
    assert_equal "<p>This is <em class=\"cool\">just</em> a test</p>\n",
      md.render("This is *just* a test")
  end

  def test_renderer_options
    parser = Redcarpet::Markdown.new(SimpleRender.new(with_toc_data: true))
    output = parser.render("# A title")

    assert_match "My little poney", output
  end

  def test_markdown_options
    parser = Redcarpet::Markdown.new(SimpleRender, no_intra_emphasis: true)
    output = parser.render("*foo*")

    assert_match "no_intra_emphasis", output
  end

  class NilPreprocessRenderer < Redcarpet::Render::HTML
    def preprocess(fulldoc)
      nil
    end
  end

  def test_preprocess_returning_nil
    md = Redcarpet::Markdown.new(NilPreprocessRenderer)
    assert_equal(nil,md.render("Anything"))
  end

  def test_base_render_without_quote_callback
    # Regression test for https://github.com/vmg/redcarpet/issues/569
    render = Class.new(Redcarpet::Render::Base)
    parser = Redcarpet::Markdown.new render.new, quote: true

    assert_equal "", parser.render(%(a "quote"))
  end
end

Version data entries

17 entries across 13 versions & 5 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.13 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.12.1 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.11 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.9 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.8 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.7 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.6 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.5 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/redcarpet-3.4.0/test/custom_render_test.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/redcarpet-3.4.0/test/custom_render_test.rb
tdiary-5.0.4 vendor/bundle/gems/redcarpet-3.4.0/test/custom_render_test.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/redcarpet-3.4.0/test/custom_render_test.rb
redcarpet-3.4.0 test/custom_render_test.rb