# coding: UTF-8 require 'test_helper' class HTMLRenderTest < Redcarpet::TestCase def setup @renderer = Redcarpet::Render::HTML end # Hint: overrides filter_html, no_images and no_links def test_that_escape_html_works source = <NO EOS expected = <Through <em>NO</em> <script>DOUBLE NO</script>

<script>BAD</script>

<img src="/favicon.ico" />

EOE assert_equal expected, render(source, with: [:escape_html]) end def test_that_filter_html_works markdown = 'Through NO ' output = render(markdown, with: [:filter_html]) assert_equal "

Through NO DOUBLE NO

\n", output end def test_filter_html_doesnt_break_two_space_hard_break markdown = "Lorem, \nipsum\n" output = render(markdown, with: [:filter_html]) assert_equal "

Lorem,
\nipsum

\n", output end def test_that_no_image_flag_works markdown = %(![dust mite](http://dust.mite/image.png) ) output = render(markdown, with: [:no_images]) assert_no_match %r{links) output = render(markdown, with: [:no_links]) assert_no_match %r{[IRC](irc://chat.freenode.org/#freenode)

\n", output end def test_that_hard_wrap_works markdown = <}, output end def test_that_link_attributes_work rndr = Redcarpet::Render::HTML.new(:link_attributes => {:rel => 'blank'}) md = Redcarpet::Markdown.new(rndr) assert md.render('This is a [simple](http://test.com) test.').include?('rel="blank"') end def test_that_link_works_with_quotes markdown = %([This'link"is](http://example.net/)) expected = %(

This'link"is

\n) assert_equal expected, render(markdown) assert_equal expected, render(markdown, with: [:escape_html]) end def test_that_code_emphasis_work markdown = <<-MD This should be **`a bold codespan`** However, this should be *`an emphasised codespan`* * **`ABC`** or **`DEF`** * Foo bar MD html = <This should be a bold codespan However, this should be an emphasised codespan

  • ABC or DEF
  • Foo bar
HTML assert_equal html, render(markdown) end def test_that_parenthesis_are_handled_into_links markdown = %(The [bash man page](man:bash(1))!) expected = %(

The bash man page!

\n) assert_equal expected, render(markdown) end def test_autolinking_works_as_expected markdown = "Uri ftp://user:pass@example.com/. Email foo@bar.com and link http://bar.com" output = render(markdown, with: [:autolink]) assert output.include? 'ftp://user:pass@example.com/' assert output.include? 'mailto:foo@bar.com' assert output.include? '' end def test_that_footnotes_work markdown = <<-MD This is a footnote.[^1] [^1]: It provides additional information. MD html = <This is a footnote.1


  1. It provides additional information. 

HTML output = render(markdown, with: [:footnotes]) assert_equal html, output end def test_footnotes_enabled_but_missing_marker markdown = <Some text without a marker

[^1] And a trailing definition

HTML output = render(markdown, with: [:footnotes]) assert_equal html, output end def test_footnotes_enabled_but_missing_definition markdown = "Some text with a marker[^1] but no definition." expected = "

Some text with a marker[^1] but no definition.

\n" output = render(markdown, with: [:footnotes]) assert_equal expected, 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" output = render(markdown, with: [:autolink]) assert output.include? 'ftp://auto/short/domains' assert output.include? 'mailto:auto@l.n' assert output.include? 'http://a/u/t/o/s/h/o/r/t' end def test_that_prettify_works markdown = "\tclass Foo\nend" output = render(markdown, with: [:prettify]) assert output.include?("
")

    markdown = "`class`"
    output   = render(markdown, with: [:prettify])

    assert output.include?("")
  end

  def test_prettify_with_fenced_code_blocks
    markdown = "~~~ruby\ncode\n~~~"
    output   = render(markdown, with: [:fenced_code_blocks, :prettify])

    assert output.include?("")
  end

  def test_safe_links_only_with_anchors
    markdown = "An [anchor link](#anchor) on a page."
    output   = render(markdown, with: [:safe_links_only])

    assert_match %r{anchor link}, output
  end

  def test_autolink_with_link_attributes
    options = { autolink: true, link_attributes: {rel: "nofollow"} }
    output  = render("https://github.com/", with: options)

    assert_match %r{rel="nofollow"}, output
  end

  def test_image_unsafe_src_with_safe_links_only
    markdown = "![foo](javascript:while(1);)"
    output   = render(markdown, with: [:safe_links_only])

    assert_not_match %r{img src}, output
  end

  def test_no_styles_option_inside_a_paragraph
    markdown = "Hello  !"
    output   = render(markdown, with: [:no_styles])

    assert_no_match %r{"
    output   = render(markdown, with: [:no_styles])

    assert_no_match %r{