Mailspring/internal_packages/message-list/lib/plugins/autolinker-extension.coffee
Juan Tejada cd1ee3f672 fix(extension-adapter): Update adapter to support all versions of extension api we've used
Summary:
- Rewrites composer extension adpater to support all versions of the
  ComposerExtension API we've ever declared. This will allow old plugins (or
  plugins that haven't been reinstalled after update) to keep functioning
  without breaking N1
- Adds specs

Test Plan: - Unit tests

Reviewers: evan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2399
2015-12-30 15:11:37 -05:00

16 lines
677 B
CoffeeScript

Autolinker = require 'autolinker'
{MessageViewExtension} = require 'nylas-exports'
class AutolinkerExtension extends MessageViewExtension
@formatMessageBody: ({message}) ->
# Apply the autolinker pass to make emails and links clickable
message.body = Autolinker.link(message.body, {twitter: false})
# Ensure that the hrefs in the email always have alt text so you can't hide
# the target of links
# https://regex101.com/r/cH0qM7/1
message.body = message.body.replace /href[ ]*=[ ]*?['"]([^'"]*)(['"]+)/gi, (match, url, quoteCharacter) =>
return "#{match} title=#{quoteCharacter}#{url}#{quoteCharacter} "
module.exports = AutolinkerExtension