# 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 = <<-HTML.strip_heredoc Through NO HTML expected = <<-HTML.chomp.strip_heredoc
Through <em>NO</em> <script>DOUBLE NO</script>
<script>BAD</script>
<img src="/favicon.ico" />
HTML 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
", 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
This should be a bold codespan
However, this should be an emphasised codespan
ABC
or DEF
The bash man page!
) 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 = <<-Markdown.strip_heredoc This is a footnote.[^1] [^1]: It provides additional information. Markdown html = <<-HTML.chomp.strip_heredocThis is a footnote.1
It provides additional information. ↩
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.
" 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{