diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 150ac9b9..610cfd72 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -324,5 +324,29 @@ module TodosHelper def auto_complete_result2(entries, phrase = nil) return entries.map{|e| e.specification()}.join("\n") rescue '' end - + + AUTO_LINK_MESSAGE_RE = %r{message://<[^>]+>} unless const_defined?(:AUTO_LINK_MESSAGE_RE) + + # Converts message:// links to href. This URL scheme is used on Mac OS X + # to link to a mail message in Mail.app. + def auto_link_message(text) + text.gsub(AUTO_LINK_MESSAGE_RE) do + href = $& + left, right = $`, $' + # detect already linked URLs and URLs in the middle of a tag + if left =~ /<[^>]+$/ && right =~ /^[^>]*>/ + # do not change string; URL is alreay linked + href + else + content_tag(:a, h(href), :href => h(href)) + end + end + end + + def format_note(note) + note = auto_link_message(note) + note = auto_link(note) + note = markdown(note) + note = sanitize(note) + end end diff --git a/app/views/notes/_notes.rhtml b/app/views/notes/_notes.rhtml index a41796a4..4ae528e0 100644 --- a/app/views/notes/_notes.rhtml +++ b/app/views/notes/_notes.rhtml @@ -2,8 +2,8 @@