diff options
author | Nick Thomas <nick@gitlab.com> | 2016-10-06 22:55:27 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2016-10-07 02:54:26 +0100 |
commit | dd159a750b294ee89cb8a4143284ff9788b639fc (patch) | |
tree | b70548ebd7173130a5c32903874f527175943671 /app/helpers/search_helper.rb | |
parent | 109816c42fbe44fca108b52308a5fa4366876216 (diff) | |
download | gitlab-ce-dd159a750b294ee89cb8a4143284ff9788b639fc.tar.gz |
Make search results use the markdown cache columns, treating them consistently
Truncato is introduced as a dependency to intelligently shorten the rendered
HTML to 200 characters; the previous approach could have resulted in invalid
HTML being rendered.
Diffstat (limited to 'app/helpers/search_helper.rb')
-rw-r--r-- | app/helpers/search_helper.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 8a7446b7cc7..aba3a3f9c5d 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -153,8 +153,18 @@ module SearchHelper search_path(options) end - # Sanitize html generated after parsing markdown from issue description or comment - def search_md_sanitize(html) + # Sanitize a HTML field for search display. Most tags are stripped out and the + # maximum length is set to 200 characters. + def search_md_sanitize(object, field) + html = markdown_field(object, field) + html = Truncato.truncate( + html, + count_tags: false, + count_tail: false, + max_length: 200 + ) + + # Truncato's filtered_tags and filtered_attributes are not quite the same sanitize(html, tags: %w(a p ol ul li pre code)) end end |