journalduhacker/spec/models/markdowner_spec.rb
joshua stein a812f25c2f Markdowner: use Nokogiri for html rewriting
brute forcing changes by regexps gets things wrong sometimes, so use
nokogiri to parse the html output of rdiscount and do changes on
individual nodes, then turn back into a string

we lose the ability to move punctuation inside of auto-generated
links, but i don't see any easy/definitive way to do this properly.

closes #242
closes #209
2015-12-07 12:27:03 -06:00

39 lines
1.3 KiB
Ruby

require "spec_helper"
describe Markdowner do
it "parses simple markdown" do
Markdowner.to_html("hello there *italics* and **bold**!").should ==
"<p>hello there <em>italics</em> and <strong>bold</strong>!</p>"
end
it "turns @username into a link if @username exists" do
User.make!(:username => "blahblah")
Markdowner.to_html("hi @blahblah test").should ==
"<p>hi <a href=\"/u/blahblah\">@blahblah</a> test</p>"
Markdowner.to_html("hi @flimflam test").should ==
"<p>hi @flimflam test</p>"
end
# bug#209
it "keeps punctuation inside of auto-generated links when using brackets" do
Markdowner.to_html("hi <http://example.com/a.> test").should ==
"<p>hi <a href=\"http://example.com/a.\" rel=\"nofollow\">" <<
"http://example.com/a.</a> test</p>"
end
# bug#242
it "does not expand @ signs inside urls" do
User.make!(:username => "blahblah")
Markdowner.to_html("hi http://example.com/@blahblah/ test").should ==
"<p>hi <a href=\"http://example.com/@blahblah/\" rel=\"nofollow\">" <<
"http://example.com/@blahblah/</a> test</p>"
Markdowner.to_html("hi [test](http://example.com/@blahblah/)").should ==
"<p>hi <a href=\"http://example.com/@blahblah/\" rel=\"nofollow\">" <<
"test</a></p>"
end
end