From 553a671fdb248922fdf1918e0032c0dced07f4de Mon Sep 17 00:00:00 2001 From: Ryan Boland Date: Tue, 30 Jul 2013 18:01:42 -0400 Subject: [PATCH] fix mentions in code blocks --- app/models/post_analyzer.rb | 3 +++ spec/models/post_analyzer_spec.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index 2e193ef41a8..58115839b4c 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -51,6 +51,9 @@ class PostAnalyzer return @raw_mentions if @raw_mentions.present? raw_stripped = @raw.gsub(/\[quote=(.*)\]([^\[]*?)\[\/quote\]/im, '') + # Process markdown so that code blocks can be generated and subsequently ignored + raw_stripped = PrettyText.markdown(raw_stripped) + # Strip pre and code tags doc = Nokogiri::HTML.fragment(raw_stripped) doc.search("pre").remove diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index 22de2416958..97671fb04a7 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -188,6 +188,11 @@ describe PostAnalyzer do post_analyzer.raw_mentions.should == ['jake'] end + it "ignores code in markdown-formatted code blocks" do + post_analyzer = PostAnalyzer.new(" @Jake @Finn\n@Ryan", default_topic_id) + post_analyzer.raw_mentions.should == ['ryan'] + end + it "ignores quotes" do post_analyzer = PostAnalyzer.new("[quote=\"Evil Trout\"]@Jake[/quote] @Finn", default_topic_id) post_analyzer.raw_mentions.should == ['finn']