correct spec, require closing tag for bbcode blocks

This commit is contained in:
Sam 2017-06-26 16:50:46 -04:00
parent e6cc07fc43
commit 21f7ac1f25
2 changed files with 20 additions and 16 deletions

View File

@ -96,7 +96,6 @@ function applyBBCode(state, startLine, endLine, silent, md) {
initial = start, initial = start,
max = state.eMarks[startLine]; max = state.eMarks[startLine];
// [ === 91 // [ === 91
if (91 !== state.src.charCodeAt(start)) { return false; } if (91 !== state.src.charCodeAt(start)) { return false; }
@ -128,9 +127,8 @@ function applyBBCode(state, startLine, endLine, silent, md) {
for (;;) { for (;;) {
nextLine++; nextLine++;
if (nextLine >= endLine) { if (nextLine >= endLine) {
// unclosed block should be autoclosed by end of document. // unclosed bbcode block should not be autoclosed by end of document.
// also block seems to be autoclosed by end of parent return false;
break;
} }
start = state.bMarks[nextLine] + state.tShift[nextLine]; start = state.bMarks[nextLine] + state.tShift[nextLine];

View File

@ -22,7 +22,7 @@ describe PrettyText do
topic = Fabricate(:topic, title: "this is a test topic :slight_smile:") topic = Fabricate(:topic, title: "this is a test topic :slight_smile:")
expected = <<HTML expected = <<HTML
<aside class="quote" data-post="2" data-topic="#{topic.id}"><div class="title"> <aside class="quote" data-post="2" data-topic="#{topic.id}"><div class="title">
<div class="quote-controls"></div><a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/emoji_one/slight_smile.png?v=5" title="slight_smile" alt="slight_smile" class="emoji"></a> <div class="quote-controls"></div><a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/twitter/slight_smile.png?v=5" title="slight_smile" alt="slight_smile" class="emoji"></a>
</div> </div>
<blockquote><p>ddd</p></blockquote></aside> <blockquote><p>ddd</p></blockquote></aside>
HTML HTML
@ -298,17 +298,17 @@ HTML
end end
it "should have an option to preserve emoji images" do it "should have an option to preserve emoji images" do
emoji_image = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt='heart'>" emoji_image = "<img src='/images/emoji/twitter/heart.png?v=1' title=':heart:' class='emoji' alt='heart'>"
expect(PrettyText.excerpt(emoji_image, 100, { keep_emoji_images: true })).to match_html(emoji_image) expect(PrettyText.excerpt(emoji_image, 100, { keep_emoji_images: true })).to match_html(emoji_image)
end end
it "should have an option to remap emoji to code points" do it "should have an option to remap emoji to code points" do
emoji_image = "I <img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'> you <img src='/images/emoji/emoji_one/heart.png?v=1' title=':unknown:' class='emoji' alt=':unknown:'> " emoji_image = "I <img src='/images/emoji/twitter/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'> you <img src='/images/emoji/twitter/heart.png?v=1' title=':unknown:' class='emoji' alt=':unknown:'> "
expect(PrettyText.excerpt(emoji_image, 100, { remap_emoji: true })).to match_html("I ❤ you :unknown:") expect(PrettyText.excerpt(emoji_image, 100, { remap_emoji: true })).to match_html("I ❤ you :unknown:")
end end
it "should have an option to preserve emoji codes" do it "should have an option to preserve emoji codes" do
emoji_code = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'>" emoji_code = "<img src='/images/emoji/twitter/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'>"
expect(PrettyText.excerpt(emoji_code, 100)).to eq(":heart:") expect(PrettyText.excerpt(emoji_code, 100)).to eq(":heart:")
end end
@ -463,10 +463,10 @@ HTML
end end
it "replaces skin toned emoji" do it "replaces skin toned emoji" do
expect(PrettyText.cook("hello 👱🏿‍♀️")).to eq("<p>hello <img src=\"/images/emoji/emoji_one/blonde_woman/6.png?v=5\" title=\":blonde_woman:t6:\" class=\"emoji\" alt=\":blonde_woman:t6:\"></p>") expect(PrettyText.cook("hello 👱🏿‍♀️")).to eq("<p>hello <img src=\"/images/emoji/twitter/blonde_woman/6.png?v=5\" title=\":blonde_woman:t6:\" class=\"emoji\" alt=\":blonde_woman:t6:\"></p>")
expect(PrettyText.cook("hello 👩‍🎤")).to eq("<p>hello <img src=\"/images/emoji/emoji_one/woman_singer.png?v=5\" title=\":woman_singer:\" class=\"emoji\" alt=\":woman_singer:\"></p>") expect(PrettyText.cook("hello 👩‍🎤")).to eq("<p>hello <img src=\"/images/emoji/twitter/woman_singer.png?v=5\" title=\":woman_singer:\" class=\"emoji\" alt=\":woman_singer:\"></p>")
expect(PrettyText.cook("hello 👩🏾‍🎓")).to eq("<p>hello <img src=\"/images/emoji/emoji_one/woman_student/5.png?v=5\" title=\":woman_student:t5:\" class=\"emoji\" alt=\":woman_student:t5:\"></p>") expect(PrettyText.cook("hello 👩🏾‍🎓")).to eq("<p>hello <img src=\"/images/emoji/twitter/woman_student/5.png?v=5\" title=\":woman_student:t5:\" class=\"emoji\" alt=\":woman_student:t5:\"></p>")
expect(PrettyText.cook("hello 🤷‍♀️")).to eq("<p>hello <img src=\"/images/emoji/emoji_one/woman_shrugging.png?v=5\" title=\":woman_shrugging:\" class=\"emoji\" alt=\":woman_shrugging:\"></p>") expect(PrettyText.cook("hello 🤷‍♀️")).to eq("<p>hello <img src=\"/images/emoji/twitter/woman_shrugging.png?v=5\" title=\":woman_shrugging:\" class=\"emoji\" alt=\":woman_shrugging:\"></p>")
end end
end end
@ -564,19 +564,19 @@ HTML
it "can handle emoji by name" do it "can handle emoji by name" do
expected = <<HTML expected = <<HTML
<p><img src="/images/emoji/emoji_one/smile.png?v=5\" title=":smile:" class="emoji" alt=":smile:"><img src="/images/emoji/emoji_one/sunny.png?v=5" title=":sunny:" class="emoji" alt=":sunny:"></p> <p><img src="/images/emoji/twitter/smile.png?v=5\" title=":smile:" class="emoji" alt=":smile:"><img src="/images/emoji/twitter/sunny.png?v=5" title=":sunny:" class="emoji" alt=":sunny:"></p>
HTML HTML
expect(PrettyText.cook(":smile::sunny:")).to eq(expected.strip) expect(PrettyText.cook(":smile::sunny:")).to eq(expected.strip)
end end
it "handles emoji boundaries correctly" do it "handles emoji boundaries correctly" do
cooked = PrettyText.cook("a,:man:t2:,b") cooked = PrettyText.cook("a,:man:t2:,b")
expected = '<p>a,<img src="/images/emoji/emoji_one/man/2.png?v=5" title=":man:t2:" class="emoji" alt=":man:t2:">,b</p>' expected = '<p>a,<img src="/images/emoji/twitter/man/2.png?v=5" title=":man:t2:" class="emoji" alt=":man:t2:">,b</p>'
expect(cooked).to match(expected.strip) expect(cooked).to match(expected.strip)
end end
it "can handle emoji by translation" do it "can handle emoji by translation" do
expected = '<p><img src="/images/emoji/emoji_one/wink.png?v=5" title=":wink:" class="emoji" alt=":wink:"></p>' expected = '<p><img src="/images/emoji/twitter/wink.png?v=5" title=":wink:" class="emoji" alt=":wink:"></p>'
expect(PrettyText.cook(";)")).to eq(expected) expect(PrettyText.cook(";)")).to eq(expected)
end end
@ -636,6 +636,12 @@ HTML
expect(PrettyText.cook("a[i]b[/i]c")).to eq('<p>a<span class="bbcode-i">b</span>c</p>') expect(PrettyText.cook("a[i]b[/i]c")).to eq('<p>a<span class="bbcode-i">b</span>c</p>')
end end
it "can handle quote edge cases" do
# expect(cook("a\n[quote]\ntest\n[quote]")).to include('aside')
expect(cook("[quote]\ntest")).not_to include('aside')
# expect(cook("[quote]abc\ntest\n[quote]")).not_to include('aside')
end
it "do off topic quoting with emoji unescape" do it "do off topic quoting with emoji unescape" do
topic = Fabricate(:topic, title: "this is a test topic :slight_smile:") topic = Fabricate(:topic, title: "this is a test topic :slight_smile:")
@ -643,7 +649,7 @@ HTML
<aside class="quote" data-topic="#{topic.id}" data-post="2"> <aside class="quote" data-topic="#{topic.id}" data-post="2">
<div class="title"> <div class="title">
<div class="quote-controls"></div> <div class="quote-controls"></div>
<a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/emoji_one/slight_smile.png?v=5" title="slight_smile" alt="slight_smile" class="emoji"></a> <a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/twitter/slight_smile.png?v=5" title="slight_smile" alt="slight_smile" class="emoji"></a>
</div> </div>
<blockquote> <blockquote>
<p>ddd</p> <p>ddd</p>