revert to old dtext spoiler behavior
This commit is contained in:
@@ -19,7 +19,6 @@ class DText
|
||||
str.gsub!(/\[i\](.+?)\[\/i\]/i, '<em>\1</em>')
|
||||
str.gsub!(/\[s\](.+?)\[\/s\]/i, '<s>\1</s>')
|
||||
str.gsub!(/\[u\](.+?)\[\/u\]/i, '<u>\1</u>')
|
||||
str.gsub!(/\[spoilers?\](.+?)\[\/spoilers?\]/i, '<span class="spoiler">\1</span>')
|
||||
|
||||
str = parse_links(str)
|
||||
str = parse_aliased_wiki_links(str)
|
||||
@@ -131,8 +130,8 @@ class DText
|
||||
str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n")
|
||||
str.gsub!(/\s*\[code\]\s*/m, "\n\n[code]\n\n")
|
||||
str.gsub!(/\s*\[\/code\]\s*/m, "\n\n[/code]\n\n")
|
||||
str.gsub!(/\[spoilers?\]\s+/m, "\n\n[spoiler]\n\n")
|
||||
str.gsub!(/\s+\[\/spoilers?\]/m, "\n\n[/spoiler]\n\n")
|
||||
str.gsub!(/\s*\[spoilers?\](?!\])\s*/m, "\n\n[spoiler]\n\n")
|
||||
str.gsub!(/\s*\[\/spoilers?\]\s*/m, "\n\n[/spoiler]\n\n")
|
||||
str.gsub!(/^(h[1-6]\.\s*.+)$/, "\n\n\\1\n\n")
|
||||
str.gsub!(/\s*\[expand(\=[^\]]*)?\]\s*/m, "\n\n[expand\\1]\n\n")
|
||||
str.gsub!(/\s*\[\/expand\]\s*/m, "\n\n[/expand]\n\n")
|
||||
|
||||
@@ -5,40 +5,71 @@ class DTextTest < ActiveSupport::TestCase
|
||||
DText.parse(s)
|
||||
end
|
||||
|
||||
def test_sanitize
|
||||
def test_sanitize_less_than
|
||||
assert_equal('<p><</p>', p("<"))
|
||||
end
|
||||
|
||||
def test_sanitize_greater_than
|
||||
assert_equal('<p>></p>', p(">"))
|
||||
end
|
||||
|
||||
def test_sanitize_ampersand
|
||||
assert_equal('<p>&</p>', p("&"))
|
||||
end
|
||||
|
||||
def test_wiki_links
|
||||
assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=b\">b</a> c</p>", p("a [[b]] c"))
|
||||
end
|
||||
|
||||
def test_wiki_links_spoiler
|
||||
assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=spoiler\">spoiler</a> c</p>", p("a [[spoiler]] c"))
|
||||
end
|
||||
|
||||
def test_spoilers
|
||||
assert_equal("<p>this is <span class=\"spoiler\">an inline spoiler</span>.</p>", p("this is [spoiler]an inline spoiler[/spoiler]."))
|
||||
def test_spoilers_inline
|
||||
assert_equal("<p>this is</p><div class=\"spoiler\"><p>an inline spoiler</p></div><p>.</p>", p("this is [spoiler]an inline spoiler[/spoiler]."))
|
||||
end
|
||||
|
||||
def test_spoilers_block
|
||||
assert_equal("<p>this is</p><div class=\"spoiler\"><p>a block spoiler</p></div><p>.</p>", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler]."))
|
||||
assert_equal("<p>[spoiler]this is a spoiler with no closing tag</p><p>new text</p>", p("[spoiler]this is a spoiler with no closing tag\n\nnew text"))
|
||||
assert_equal("<p>[spoiler]this is a spoiler with no closing tag<br>new text</p>", p("[spoiler]this is a spoiler with no closing tag\nnew text"))
|
||||
assert_equal("<p><span class=\"spoiler\">this is [spoiler]a nested</span> spoiler[/spoiler]</p>", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]"))
|
||||
end
|
||||
|
||||
def test_spoilers_with_no_closing_tag_1
|
||||
assert_equal("<div class=\"spoiler\">\n<p>this is a spoiler with no closing tag</p>\n<p>new text</p>\n</div>", p("[spoiler]this is a spoiler with no closing tag\n\nnew text"))
|
||||
end
|
||||
|
||||
def test_spoilers_with_no_closing_tag_2
|
||||
assert_equal("<div class=\"spoiler\"><p>this is a spoiler with no closing tag<br>new text</p></div>", p("[spoiler]this is a spoiler with no closing tag\nnew text"))
|
||||
end
|
||||
|
||||
def test_spoilers_with_no_closing_tag_block
|
||||
assert_equal("<div class=\"spoiler\"><p>this is a block spoiler with no closing tag</p></div>", p("[spoiler]\nthis is a block spoiler with no closing tag"))
|
||||
end
|
||||
|
||||
def test_spoilers_nested
|
||||
assert_equal("<div class=\"spoiler\">\n<p>this is</p>\n<div class=\"spoiler\"><p>a nested</p></div>\n<p>spoiler</p>\n</div>", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]"))
|
||||
end
|
||||
|
||||
def test_paragraphs
|
||||
assert_equal("<p>a</p>", p("a"))
|
||||
assert_equal("<p>abc</p>", p("abc"))
|
||||
end
|
||||
|
||||
def test_paragraphs_with_newlines_1
|
||||
assert_equal("<p>a<br>b<br>c</p>", p("a\nb\nc"))
|
||||
end
|
||||
|
||||
def test_paragraphs_with_newlines_2
|
||||
assert_equal("<p>a</p><p>b</p>", p("a\n\nb"))
|
||||
end
|
||||
|
||||
def test_headers
|
||||
assert_equal("<h1>header</h1>", p("h1. header"))
|
||||
assert_equal("<h1>header</h1><p>paragraph</p>", p("h1.header\n\nparagraph"))
|
||||
end
|
||||
|
||||
def test_quote_blocks
|
||||
assert_equal('<blockquote><p>test</p></blockquote>', p("[quote]\ntest\n[/quote]"))
|
||||
end
|
||||
|
||||
def test_quote_blocks_nested
|
||||
assert_equal("<blockquote>\n<p>a</p>\n<blockquote><p>b</p></blockquote>\n<p>c</p>\n</blockquote>", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]"))
|
||||
end
|
||||
|
||||
@@ -48,29 +79,61 @@ class DTextTest < ActiveSupport::TestCase
|
||||
|
||||
def test_urls
|
||||
assert_equal('<p>a <a href="http://test.com">http://test.com</a> b</p>', p('a http://test.com b'))
|
||||
end
|
||||
|
||||
def test_urls_with_newline
|
||||
assert_equal('<p><a href="http://test.com">http://test.com</a><br>b</p>', p("http://test.com\nb"))
|
||||
end
|
||||
|
||||
def test_urls_with_paths
|
||||
assert_equal('<p>a <a href="http://test.com/~bob/image.jpg">http://test.com/~bob/image.jpg</a> b</p>', p('a http://test.com/~bob/image.jpg b'))
|
||||
end
|
||||
|
||||
def test_urls_with_fragment
|
||||
assert_equal('<p>a <a href="http://test.com/home.html#toc">http://test.com/home.html#toc</a> b</p>', p('a http://test.com/home.html#toc b'))
|
||||
end
|
||||
|
||||
def test_auto_urls
|
||||
assert_equal('<p>a <a href="http://test.com">http://test.com</a>. b</p>', p('a http://test.com. b'))
|
||||
end
|
||||
|
||||
def test_auto_urls_in_parentheses
|
||||
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
|
||||
end
|
||||
|
||||
def test_old_syle_links
|
||||
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
|
||||
assert_equal('<p>"1" <a href="http://two.com">2</a></p>', p('"1" "2":http://two.com'))
|
||||
end
|
||||
|
||||
def test_old_style_links_with_special_entities
|
||||
assert_equal('<p>"1" <a href="http://three.com">2 & 3</a></p>', p('"1" "2 & 3":http://three.com'))
|
||||
end
|
||||
|
||||
def test_lists
|
||||
def test_lists_1
|
||||
assert_equal('<ul><li>a</li></ul>', p('* a'))
|
||||
end
|
||||
|
||||
def test_lists_2
|
||||
assert_equal('<ul><li>a</li><li>b</li></ul>', p("* a\n* b").gsub(/\n/, ""))
|
||||
end
|
||||
|
||||
def test_lists_nested
|
||||
assert_equal('<ul><li>a</li><ul><li>b</li></ul></ul>', p("* a\n** b").gsub(/\n/, ""))
|
||||
end
|
||||
|
||||
def test_lists_inline
|
||||
assert_equal('<ul><li><a href="/posts/1">post #1</a></li></ul>', p("* post #1").gsub(/\n/, ""))
|
||||
end
|
||||
|
||||
def test_inline
|
||||
def test_inline_tags
|
||||
assert_equal('<p><a href="/posts?tags=tag">tag</a></p>', p("{{tag}}"))
|
||||
end
|
||||
|
||||
def test_inline_tags_conjunction
|
||||
assert_equal('<p><a href="/posts?tags=tag1+tag2">tag1 tag2</a></p>', p("{{tag1 tag2}}"))
|
||||
end
|
||||
|
||||
def test_inline_tags_special_entities
|
||||
assert_equal('<p><a href="/posts?tags=%3C3"><3</a></p>', p("{{<3}}"))
|
||||
end
|
||||
|
||||
@@ -78,8 +141,11 @@ class DTextTest < ActiveSupport::TestCase
|
||||
assert_equal('<p>a</p><p>b</p>', p("a\n\n\n\n\n\n\nb\n\n\n\n"))
|
||||
end
|
||||
|
||||
def test_complex_links
|
||||
def test_complex_links_1
|
||||
assert_equal("<p><a href=\"/wiki_pages/show_or_new?title=1\">2 3</a> | <a href=\"/wiki_pages/show_or_new?title=4\">5 6</a></p>", p("[[1|2 3]] | [[4|5 6]]"))
|
||||
end
|
||||
|
||||
def test_complex_links_2
|
||||
assert_equal("<p>Tags <strong>(<a href=\"/wiki_pages/show_or_new?title=howto%3Atag\">Tagging Guidelines</a> | <a href=\"/wiki_pages/show_or_new?title=howto%3Atag_checklist\">Tag Checklist</a> | <a href=\"/wiki_pages/show_or_new?title=tag_groups\">Tag Groups</a>)</strong></p>", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]"))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user