add target="_blank" for generated links

This causes the links to be opened in a new window/tab.
Existing (rendered) notes are not affected by this.

Fixes #1747
This commit is contained in:
Carsten Otto 2016-01-23 19:19:53 +01:00
parent d1a9e2746b
commit 3327966af1
2 changed files with 22 additions and 8 deletions

View file

@ -25,14 +25,17 @@ module Tracks
def self.render_text(text)
rendered = auto_link_message(text)
rendered = textile(rendered)
rendered = helpers.auto_link(rendered, :link => :urls)
rendered = helpers.auto_link(rendered, :link => :urls, :html => {:target => '_blank'})
# add onenote and message protocols
config = Sanitize::Config.merge(Sanitize::Config::RELAXED,
:protocols => { 'a' => {'href' => Sanitize::Config::RELAXED[:protocols]['a']['href'] + ['onenote', 'message']}}
)
relaxed_config = Sanitize::Config::RELAXED
config = relaxed_config
rendered = Sanitize.clean(rendered, config)
# add onenote and message protocols, allow a target
a_href_config = relaxed_config[:protocols]['a']['href'] + %w(onenote message)
a_attributes = relaxed_config[:attributes]['a'] + ['target']
config = Sanitize::Config.merge(config, :protocols => {'a' => {'href' => a_href_config}}, :attributes => {'a' => a_attributes})
rendered = Sanitize.fragment(rendered, config)
return rendered.html_safe
end