Linkify message:// URLs in notes. Those links are used by Mail.app on

Mac OS X to link to a mail message by message id.
This commit is contained in:
Patrice Neff 2010-01-10 02:47:54 +08:00 committed by Eric Allen
parent e844b5aa5b
commit 5299490c83
5 changed files with 69 additions and 5 deletions

View file

@ -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

View file

@ -2,8 +2,8 @@
<div id="<%= dom_id(note, 'container') %>">
<h2><%= link_to("Note #{note.id}", note_path(note), :title => "Show note #{note.id}" ) %></h2>
<div class="project_notes" id="<%= dom_id(note) %>">
<%= sanitize(markdown(auto_link(note.body))) %>
<%= format_note(note.body) %>
<div class="note_footer">
<%= link_to_remote(
image_tag("blank.png",

View file

@ -1,5 +1,5 @@
<%= link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_notes', :title => 'Show notes'}) %>
<div class="todo_notes" id="<%= dom_id(item, 'notes') %>" style="display:none">
<%= sanitize(markdown( auto_link(item.notes)) ) %>
<%= format_note(item.notes) %>
</div>