diff --git a/app/assets/javascripts/discourse/dialects/html.js b/app/assets/javascripts/discourse/dialects/html.js index 9213fa36c8..5de0a39056 100644 --- a/app/assets/javascripts/discourse/dialects/html.js +++ b/app/assets/javascripts/discourse/dialects/html.js @@ -1,8 +1,18 @@ /** If a row begins with HTML tags, don't parse it. **/ +var blockTags = ['address', 'article', 'aside', 'audio', 'blockquote', 'canvas', 'dd', 'div', + 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', + 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'noscript', 'ol', 'output', + 'p', 'pre', 'section', 'table', 'tfoot', 'ul', 'video']; + Discourse.Dialect.registerBlock('html', function(block, next) { - if (block.match(/^<[^>]+\>/)) { - return [ block.toString() ]; + + var m = /^<([^>]+)\>/.exec(block); + if (m && m[1]) { + var tag = m[1].split(/\s/); + if (tag && tag[0] && blockTags.indexOf(tag[0]) !== -1) { + return [ block.toString() ]; + } } }); \ No newline at end of file diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index d85e245625..8625496b62 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -32,7 +32,7 @@ describe PrettyText do end it "should sanitize the html" do - PrettyText.cook("").should match_html "" + PrettyText.cook("").should match_html "

" end it 'should allow for @mentions to have punctuation' do diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index 5d000e8b5f..4e465dfd99 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -56,6 +56,14 @@ test("Line Breaks", function() { "it handles new lines correctly with [] options"); }); +test("Paragraphs for HTML", function() { + cooked("
hello world
", "
hello world
", "it doesn't surround
with paragraphs"); + cooked("

hello world

", "

hello world

", "it doesn't surround

with paragraphs"); + cooked("hello world", "

hello world

", "it surrounds inline html tags with paragraphs"); + cooked("hello world", "

hello world

", "it surrounds inline html tags with paragraphs"); + +}); + test("Links", function() { cooked("EvilTrout: http://eviltrout.com", @@ -300,7 +308,7 @@ test("sanitize", function() { cooked("hello", "

hello

", "it sanitizes while cooking"); cooked("disney reddit", - "disney reddit", + "

disney reddit

", "we can embed proper links"); }); diff --git a/test/javascripts/mdtest/fixtures/Amps and angle encoding.xhtml b/test/javascripts/mdtest/fixtures/Amps and angle encoding.xhtml index c458eb0351..483f8ffa16 100755 --- a/test/javascripts/mdtest/fixtures/Amps and angle encoding.xhtml +++ b/test/javascripts/mdtest/fixtures/Amps and angle encoding.xhtml @@ -1,8 +1,3 @@ -

AT&T has an ampersand in their name.

AT&T is another way to write it.

diff --git a/test/javascripts/mdtest/fixtures/Backslash escapes.xhtml b/test/javascripts/mdtest/fixtures/Backslash escapes.xhtml index 6c54bdc68d..750830e8c9 100755 --- a/test/javascripts/mdtest/fixtures/Backslash escapes.xhtml +++ b/test/javascripts/mdtest/fixtures/Backslash escapes.xhtml @@ -1,10 +1,3 @@ -

These should all get escaped:

Backslash: \

diff --git a/test/javascripts/mdtest/fixtures/Blockquotes with code blocks.xhtml b/test/javascripts/mdtest/fixtures/Blockquotes with code blocks.xhtml index 2f9c92bef0..cb34534995 100755 --- a/test/javascripts/mdtest/fixtures/Blockquotes with code blocks.xhtml +++ b/test/javascripts/mdtest/fixtures/Blockquotes with code blocks.xhtml @@ -1,8 +1,3 @@ -

Example:

diff --git a/test/javascripts/mdtest/fixtures/Code Spans.xhtml b/test/javascripts/mdtest/fixtures/Code Spans.xhtml index b28505047b..e050061d89 100755 --- a/test/javascripts/mdtest/fixtures/Code Spans.xhtml +++ b/test/javascripts/mdtest/fixtures/Code Spans.xhtml @@ -1,10 +1,3 @@ -

<test a=" content of attribute ">

Fix for backticks within HTML tag: like this

diff --git a/test/javascripts/mdtest/fixtures/Inline HTML (Advanced).xhtml b/test/javascripts/mdtest/fixtures/Inline HTML (Advanced).xhtml index 1914c2a435..fc51e2a27e 100755 --- a/test/javascripts/mdtest/fixtures/Inline HTML (Advanced).xhtml +++ b/test/javascripts/mdtest/fixtures/Inline HTML (Advanced).xhtml @@ -1,9 +1,3 @@ -

Simple block on one line:

foo
diff --git a/test/javascripts/mdtest/fixtures/Inline HTML (Simple).xhtml b/test/javascripts/mdtest/fixtures/Inline HTML (Simple).xhtml index f872b90480..25067beea3 100755 --- a/test/javascripts/mdtest/fixtures/Inline HTML (Simple).xhtml +++ b/test/javascripts/mdtest/fixtures/Inline HTML (Simple).xhtml @@ -1,8 +1,3 @@ -

Here's a simple block:

diff --git a/test/javascripts/mdtest/fixtures/Links, inline style.xhtml b/test/javascripts/mdtest/fixtures/Links, inline style.xhtml index 5802fe612a..aca7a2a4ad 100755 --- a/test/javascripts/mdtest/fixtures/Links, inline style.xhtml +++ b/test/javascripts/mdtest/fixtures/Links, inline style.xhtml @@ -1,8 +1,3 @@ -

Just a URL.

URL and title.

diff --git a/test/javascripts/mdtest/fixtures/Markdown Documentation - Basics.xhtml b/test/javascripts/mdtest/fixtures/Markdown Documentation - Basics.xhtml index 2b85112ab2..e971a195a4 100755 --- a/test/javascripts/mdtest/fixtures/Markdown Documentation - Basics.xhtml +++ b/test/javascripts/mdtest/fixtures/Markdown Documentation - Basics.xhtml @@ -1,8 +1,3 @@ -

Markdown: Basics

    diff --git a/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml b/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml index fb7b769352..5c6b9e32b7 100755 --- a/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml +++ b/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml @@ -1,8 +1,3 @@ -

    Markdown: Syntax

      diff --git a/test/javascripts/mdtest/mdtest.js.erb b/test/javascripts/mdtest/mdtest.js.erb index 0384b3464c..ca1f5b9f0e 100644 --- a/test/javascripts/mdtest/mdtest.js.erb +++ b/test/javascripts/mdtest/mdtest.js.erb @@ -19,7 +19,6 @@ var md = function(input, expected, text) { expectedNorm = normalize(expected), same = (result === expected) || (resultNorm === expectedNorm); - if (same) { ok(same, text); } else { @@ -42,7 +41,7 @@ test("first", function(){ filename = Pathname.new(filename_no_ext) text = File.read(f) - html = File.read("#{filename_no_ext}.xhtml").gsub(/\<\!\-\-(.*?)\-\-\>/m, '') + html = File.read("#{filename_no_ext}.xhtml"); result << "test(\"#{filename}\", function() { md(#{text.to_json}, #{html.to_json}, 'passes MDTest'); });\n" end result