From 9a6606dd305f4f32ed464838fb4d85ac4788f259 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Sat, 4 Jan 2020 18:56:52 +0530 Subject: [PATCH] DEV: Add option to keep quoted content in post excerpt. --- lib/excerpt_parser.rb | 7 +++++-- spec/components/excerpt_parser_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 479c46ef999..9f11c1f45f8 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -19,6 +19,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document @keep_emoji_images = options[:keep_emoji_images] == true @keep_onebox_source = options[:keep_onebox_source] == true @keep_onebox_body = options[:keep_onebox_body] == true + @keep_quotes = options[:keep_quotes] == true @remap_emoji = options[:remap_emoji] == true @start_excerpt = false @in_details_depth = 0 @@ -100,8 +101,10 @@ class ExcerptParser < Nokogiri::XML::SAX::Document @in_quote = true end - if @keep_onebox_body && attributes['class'].include?('quote') && attributes['data-topic'].present? - @in_quote = false + if attributes['class'].include?('quote') + if @keep_quotes || (@keep_onebox_body && attributes['data-topic'].present?) + @in_quote = false + end end when 'article' diff --git a/spec/components/excerpt_parser_spec.rb b/spec/components/excerpt_parser_spec.rb index ff11ec55783..8f0654bab5f 100644 --- a/spec/components/excerpt_parser_spec.rb +++ b/spec/components/excerpt_parser_spec.rb @@ -81,4 +81,17 @@ describe ExcerptParser do HTML end end + + describe "keep_quotes parameter" do + it "should keep the quoted content in html" do + html = <<~HTML.strip + + HTML + expect(ExcerptParser.get_excerpt(html, 100, keep_quotes: true)).to eq("This is a quoted text.") + end + end end