discourse/spec/integrity/common_mark_spec.rb

74 lines
2.2 KiB
Ruby
Raw Normal View History

2017-07-21 12:20:45 -05:00
# frozen_string_literal: true
RSpec.describe "CommonMark" do
it "passes spec" do
2017-07-21 12:20:45 -05:00
SiteSetting.traditional_markdown_linebreaks = true
SiteSetting.enable_markdown_typographer = false
SiteSetting.highlighted_languages = "ruby|aa"
2017-07-21 12:20:45 -05:00
2017-07-27 20:20:09 -05:00
html, state, md = nil
2017-07-21 12:20:45 -05:00
failed = 0
File
.readlines(Rails.root + "spec/fixtures/md/spec.txt")
.each do |line|
if line == "```````````````````````````````` example\n"
state = :example
next
end
2017-07-21 12:20:45 -05:00
if line == "````````````````````````````````\n"
md.gsub!("", "\t")
html ||= String.new
html.gsub!("", "\t")
html.strip!
2017-07-21 12:20:45 -05:00
# normalize brs
html.gsub!("<br />", "<br>")
html.gsub!("<hr />", "<hr>")
html.gsub!(%r{<img([^>]+) />}, "<img\\1>")
2017-07-21 12:20:45 -05:00
SiteSetting.enable_markdown_linkify = false
cooked = PrettyText.markdown(md, sanitize: false)
cooked.strip!
cooked.gsub!(" class=\"lang-auto\"", "")
cooked.gsub!(%r{<span class="hashtag-raw">(.*)</span>}, "\\1")
cooked.gsub!(%r{<a name="(.*)" class="anchor" href="#\1*"></a>}, "")
# we support data-attributes which is not in the spec
cooked.gsub!("<pre data-code-startline=\"3\">", "<pre>")
# we don't care about this
cooked.gsub!("<blockquote>\n</blockquote>", "<blockquote></blockquote>")
html.gsub!("<blockquote>\n</blockquote>", "<blockquote></blockquote>")
html.gsub!("language-ruby", "lang-ruby")
html.gsub!("language-aa", "lang-aa")
# strip out unsupported languages
html.gsub!(%r{ class="language-[;f].*"}, "")
2017-07-21 12:20:45 -05:00
unless cooked == html
failed += 1
puts "FAILED SPEC"
puts "Expected: "
puts html
puts "Got: "
puts cooked
puts "Markdown: "
puts md
puts
end
html, state, md = nil
next
2017-07-21 12:20:45 -05:00
end
if state == :example && line == ".\n"
state = :html
next
end
2017-07-21 12:20:45 -05:00
md = (md || String.new) << line if state == :example
2017-07-21 12:20:45 -05:00
html = (html || String.new) << line if state == :html
2017-07-21 12:20:45 -05:00
end
expect(failed).to eq(0)
end
end