mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-20 22:23:53 +08:00
fix(autolinker): Add title attr to all links in emails to display href
Fixes GitHub Issues #479 and #335
This commit is contained in:
parent
0a413a1598
commit
79413e7c45
2 changed files with 34 additions and 0 deletions
|
@ -7,4 +7,10 @@ class AutolinkerExtension extends MessageStoreExtension
|
|||
# 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
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
Autolinker = require 'autolinker'
|
||||
AutolinkerExtension = require '../lib/plugins/autolinker-extension'
|
||||
|
||||
describe "AutolinkerExtension", ->
|
||||
beforeEach ->
|
||||
spyOn(Autolinker, 'link').andCallFake (txt) => txt
|
||||
|
||||
it "should call through to Autolinker", ->
|
||||
AutolinkerExtension.formatMessageBody({body:'body'})
|
||||
expect(Autolinker.link).toHaveBeenCalledWith('body', {twitter: false})
|
||||
|
||||
it "should add a title to everything with an href", ->
|
||||
message =
|
||||
body: """
|
||||
<a href="apple.com">hello world!</a>
|
||||
<a href = "http://apple.com">hello world!</a>
|
||||
<a href ='http://apple.com'>hello world!</a>
|
||||
<a href ='mailto://'>hello world!</a>
|
||||
"""
|
||||
expected =
|
||||
body: """
|
||||
<a href="apple.com" title="apple.com" >hello world!</a>
|
||||
<a href = "http://apple.com" title="http://apple.com" >hello world!</a>
|
||||
<a href ='http://apple.com' title='http://apple.com' >hello world!</a>
|
||||
<a href ='mailto://' title='mailto://' >hello world!</a>
|
||||
"""
|
||||
AutolinkerExtension.formatMessageBody(message)
|
||||
expect(message.body).toEqual(expected.body)
|
Loading…
Reference in a new issue