Fix #2598 for old parser

This commit is contained in:
Type-kun
2016-09-06 01:06:29 +05:00
parent 3152daa47a
commit 8c04a9d390
2 changed files with 15 additions and 2 deletions

View File

@@ -193,7 +193,7 @@ class DText
str.gsub!(/\[\/code\]\s*/m, "\n\n[/code]\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!(/^(h[1-6](\#[A-z][_A-z0-9-]+)?\.\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")
str.gsub!(/\s*\[table\](?!\])\s*/m, "\n\n[table]\n\n")
@@ -217,7 +217,16 @@ class DText
else
"<#{tag}>" + parse_inline(content, options) + "</#{tag}>"
end
when /\A(h[1-6])\#([A-z][_A-z0-9-]+)\.\s*(.+)\Z/
tag = $1
header_id = $2
content = $3
if options[:inline]
"<h6 id=\"#{header_id}\">" + parse_inline(content, options) + "</h6>"
else
"<#{tag} id=\"#{header_id}\">" + parse_inline(content, options) + "</#{tag}>"
end
when /^\s*\*+ /
parse_list(block, options)

View File

@@ -75,6 +75,10 @@ class DTextTest < ActiveSupport::TestCase
def test_headers
assert_equal("<h1>header</h1>", p("h1. header"))
end
def test_headers_with_ids
assert_equal("<h1 id=\"header-id\">header</h1>", p("h1#header-id. header"))
end
def test_quote_blocks
assert_equal('<blockquote><p>test</p></blockquote>', p("[quote]\ntest\n[/quote]"))