diff --git a/Changelog.md b/Changelog.md index b6c79dd3a..eec84cdbf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -139,6 +139,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a * Total user statistic no longer includes closed accounts [#5041](https://github.com/diaspora/diaspora/pull/5041) * Don't add a space when rendering a mention [#5711](https://github.com/diaspora/diaspora/pull/5711) * Fix flickering hovercards [#5714](https://github.com/diaspora/diaspora/pull/5714) +* Improved stripping markdown in post titles [#5730](https://github.com/diaspora/diaspora/pull/5730) ## Features * Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105) diff --git a/lib/diaspora/message_renderer.rb b/lib/diaspora/message_renderer.rb index a9432c8fe..a876156f8 100644 --- a/lib/diaspora/message_renderer.rb +++ b/lib/diaspora/message_renderer.rb @@ -225,7 +225,7 @@ module Diaspora atx_content end - heading &&= heading.strip + heading &&= self.class.new(heading).plain_text_without_markdown if heading && opts[:length] heading.truncate opts[:length] diff --git a/spec/lib/diaspora/message_renderer_spec.rb b/spec/lib/diaspora/message_renderer_spec.rb index 1ee78b35d..9e152cdce 100644 --- a/spec/lib/diaspora/message_renderer_spec.rb +++ b/spec/lib/diaspora/message_renderer_spec.rb @@ -9,7 +9,7 @@ describe Diaspora::MessageRenderer do context 'when :length is passed in parameters' do it 'returns string of size less or equal to :length' do string_size = 12 - title = message("## My title\n Post content...").title(length: string_size) + title = message("## This is a really, really, really long title\n Post content").title(length: string_size) expect(title.size).to be <= string_size end end @@ -24,6 +24,10 @@ describe Diaspora::MessageRenderer do it 'returns setext style header' do expect(message("My title \n======\n Post content...").title).to eq "My title" end + + it 'returns header without markdown' do + expect(message("## **[My title](http://diasporafoundation.org)**\n Post content...").title).to eq "My title (http://diasporafoundation.org)" + end end context 'without a Markdown header of less than 200 characters on first line ' do