# encoding: utf-8 require 'minitest/autorun' require_relative '../lib/devcenter-parser' describe 'DevcenterParser' do describe '.to_unsanitized_html' do it 'maintains script tags' do md = '' assert_parsing_unsanitized_result md, :maruku, md assert_parsing_unsanitized_result md, :github, '' end end describe '.to_html' do it 'raises InvalidMarkdownError when parsing invalid markdown' do md = '[foo](bar' assert_raises DevcenterParser::InvalidMarkdownError do DevcenterParser.to_html(md, :maruku) end end it 'respects existing ids' do md = 'clean' assert_maruku_result md, 'clean' end it 'removes script tags and their content' do md = 'clean' assert_maruku_result md, 'clean' end it 'github markdown includes ids in subheaders' do md = <<-MARKDOWN ## Foo Bar Header 123 Foo bar content MARKDOWN assert DevcenterParser.to_html(md, :github).include?('
Testing
not a callout strong normal
And that's it.
HTML assert_github_result(md, html) md = <<-MARKDOWN Testing > calloutnonono > **strong** > normal And that's it. MARKDOWN html = <<-HTMLTesting
calloutnonono strong normal
And that's it.
HTML assert_github_result(md, html) end it 'github markdown supports "> callout" and ">callout" and parses inner markdown' do mds = [] mds << <<-MARKDOWN Testing > callout > **strong** > normal And that's it. MARKDOWN mds << <<-MARKDOWN Testing >callout >**strong** >normal And that's it. MARKDOWN html = <<-HTMLTesting
strong normal
And that's it.
HTML mds.each do |md| assert_github_result(md, html) end end it 'github markdown supports "> callout" and ">callout", parses inner markdown and allows paragraphs' do mds = [] mds << <<-MARKDOWN Testing > callout > **strong** > normal And that's it. MARKDOWN mds << <<-MARKDOWN Testing >callout >**strong** >normal And that's it. MARKDOWN html = <<-HTMLTesting
strong
normal
And that's it.
HTML mds.each do |md| assert_github_result(md, html) end end it "does emdashes both in all flavours" do md = "foo -- bar" html = 'foo – bar
' assert_all_flavours_result(md, html) end it 'converts relative links with missing initial slashes to article links' do ['foo', 'foo/bar', 'foo#bar', '123'].each do |href| md = "[link](#{href})" html = "" assert_maruku_result md, html assert_github_result md, html end end it 'does not alter relative links with initial slashes nor absolute links' do ['http://foo.com', 'https://foo.com', '/foo', '/foo/bar', '/foo#bar', '/123', 'mailto:foo@foobar.com'].each do |href| md = "[link](#{href})" html = "" assert_maruku_result md, html assert_github_result md, html end end end # helpers def assert_all_flavours_result(md, expected) [:github, :maruku].each { |flavour| assert_parsing_result(md, flavour, expected) } end def assert_maruku_result(md, expected) assert_parsing_result md, :maruku, expected end def assert_github_result(md, expected) assert_parsing_result md, :github, expected end def assert_parsing_result(md, flavour, expected) result = DevcenterParser.to_html(md, flavour) assert_equal expected.strip, result.strip, "Failed when parsing\n#{md}\nwith the #{flavour} flavour.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n" end def assert_parsing_unsanitized_result(md, flavour, expected) result = DevcenterParser.to_unsanitized_html(md, flavour) assert_equal expected.strip, result.strip, "Failed when parsing on unsanitized mode\n#{md}\nwith the #{flavour} flavour.\n\nExpected:\n#{expected}\n\nActual result:\n#{result}\n\n" end end