mardownify doesn't strip _/__/*/** without context anymore and allow __/** to be escaped with \__/\** instead of \_\_/\*\*. probably makes it less robust against weired constructs though

This commit is contained in:
MrZYX 2010-12-01 20:59:26 +01:00
parent 1a8e0788c2
commit c3356af8d1
2 changed files with 12 additions and 9 deletions

View file

@ -186,14 +186,17 @@ module ApplicationHelper
end
if options[:emphasis]
message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^*\\])\*\*/, '\1<strong>\2</strong>')
message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^_\\])__/, '\1<strong>\2</strong>')
message.gsub!(/([^\\]|^)\*([^*]*[^\\])\*/, '\1<em>\2</em>')
message.gsub!(/([^\\]|^)_([^_]*[^\\])_/, '\1<em>\2</em>')
message.gsub!(/([^\\]|^)\*/, '\1')
message.gsub!(/([^\\]|^)_/, '\1')
message.gsub!("\\*", "*")
message.gsub!("\\_", "_")
message.gsub!("\\**", "-^doublestar^-")
message.gsub!("\\__", "-^doublescore^-")
message.gsub!("\\*", "-^star^-")
message.gsub!("\\_", "-^score^-")
message.gsub!(/(\*\*\*|___)(.+?)\1/m, '<em><strong>\2</strong></em>')
message.gsub!(/(\*\*|__)(.+?)\1/m, '<strong>\2</strong>')
message.gsub!(/(\*|_)(.+?)\1/m, '<em>\2</em>')
message.gsub!("-^doublestar^-", "**")
message.gsub!("-^doublescore^-", "__")
message.gsub!("-^star^-", "*")
message.gsub!("-^score^-", "_")
end
if options[:youtube]

View file

@ -171,7 +171,7 @@ describe ApplicationHelper do
it "should allow escaping" do
message = '*some text* \\*some text* \\**some text* _some text_ \\_some text_ \\__some text_'
markdownify(message).should == "<em>some text</em> *some text<em> *</em>some text <em>some text</em> _some text<em> _</em>some text"
markdownify(message).should == "<em>some text</em> *some text<em> **some text</em> <em>some text</em> _some text<em> __some text</em>"
end
describe "options" do