test/html_render_test.rb in redcarpet-3.0.0 vs test/html_render_test.rb in redcarpet-3.1.0

- old
+ new

@@ -9,10 +9,12 @@ :no_images => Redcarpet::Render::HTML.new(:no_images => true), :no_links => Redcarpet::Render::HTML.new(:no_links => true), :safe_links => Redcarpet::Render::HTML.new(:safe_links_only => true), :escape_html => Redcarpet::Render::HTML.new(:escape_html => true), :hard_wrap => Redcarpet::Render::HTML.new(:hard_wrap => true), + :toc_data => Redcarpet::Render::HTML.new(:with_toc_data => true), + :prettify => Redcarpet::Render::HTML.new(:prettify => true) } end def render_with(rndr, text) Redcarpet::Markdown.new(rndr).render(text) @@ -129,11 +131,93 @@ assert output.include? '<a href="ftp://user:pass@example.com/">ftp://user:pass@example.com/</a>' assert output.include? 'mailto:foo@bar.com' assert output.include? '<a href="http://bar.com">' end - def test_that_comments_arent_escaped - input = "<!-- This is a nice comment! -->" - output = render_with(@rndr[:escape_html], input) - assert output.include? input + def test_that_footnotes_work + markdown = <<-MD +This is a footnote.[^1] + +[^1]: It provides additional information. +MD + + html = <<HTML +<p>This is a footnote.<sup id="fnref1"><a href="#fn1" rel="footnote">1</a></sup></p> + +<div class="footnotes"> +<hr> +<ol> + +<li id="fn1"> +<p>It provides additional information.&nbsp;<a href="#fnref1" rev="footnote">&#8617;</a></p> +</li> + +</ol> +</div> +HTML + + renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true) + output = renderer.render(markdown) + assert_equal html, output + end + + def test_footnotes_enabled_but_missing_marker + markdown = <<MD +Some text without a marker + +[^1] And a trailing definition +MD + html = <<HTML +<p>Some text without a marker</p> + +<p>[^1] And a trailing definition</p> +HTML + + renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true) + output = renderer.render(markdown) + assert_equal html, output + end + + def test_footnotes_enabled_but_missing_definition + markdown = "Some text with a marker[^1] but no definition." + html = "<p>Some text with a marker[^1] but no definition.</p>\n" + + renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true) + output = renderer.render(markdown) + assert_equal html, output + end + + def test_autolink_short_domains + markdown = "Example of uri ftp://auto/short/domains. Email auto@l.n and link http://a/u/t/o/s/h/o/r/t" + renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true) + output = renderer.render(markdown) + + assert output.include? '<a href="ftp://auto/short/domains">ftp://auto/short/domains</a>' + assert output.include? 'mailto:auto@l.n' + assert output.include? '<a href="http://a/u/t/o/s/h/o/r/t">http://a/u/t/o/s/h/o/r/t</a>' + end + + def test_toc_heading_id + markdown = "# First level heading\n## Second level heading" + output = render_with(@rndr[:toc_data], markdown) + assert_match /<h1 id="first-level-heading">/, output + assert_match /<h2 id="second-level-heading">/, output + end + + def test_that_prettify_works + text = <<-Markdown +Foo + +~~~ruby +some +code +~~~ + +Bar +Markdown + + renderer = Redcarpet::Markdown.new(@rndr[:prettify], fenced_code_blocks: true) + output = renderer.render(text) + + assert output.include?("<code class=\"prettyprint ruby\">") end end