From 4e255de9cb83c67ea162cb2a4598ecf61c640574 Mon Sep 17 00:00:00 2001 From: Daniel MacDougall Date: Sun, 9 Oct 2011 03:07:46 -0700 Subject: [PATCH] Automatically add links to images embedded in comments --- lib/string_filter.rb | 7 ++++++- models/comment.rb | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/string_filter.rb b/lib/string_filter.rb index de74aa89..24895090 100644 --- a/lib/string_filter.rb +++ b/lib/string_filter.rb @@ -8,7 +8,6 @@ # # Possible extensions: # * Convert APP-XXX to jira links -# * Convert an image link (![alt][link] syntax) to a be a link to the image as well # * Make @username link to profile pages module StringFilter @@ -31,6 +30,12 @@ def link_github_issue(github_username, github_repo) end end + # Converts an embedded image (![alt][link]) to also include + # a link to the same image + def link_embedded_images + self.gsub(/!\[.*\]\((.*)\)/) { |match| "[#{match}](#{$1})" } + end + def newlines_to_html self.gsub("\n", "
") end diff --git a/models/comment.rb b/models/comment.rb index 1ad669bb..07c7be08 100644 --- a/models/comment.rb +++ b/models/comment.rb @@ -18,7 +18,8 @@ def general_comment?() commit_file_id.nil? end def file_comment?() !commit_file_id.nil? end def format - text.markdown + text.link_embedded_images + .markdown .replace_shas_with_links(commit.git_repo.name) end end