mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-04-08 05:21:15 +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
e0e6a288f1
commit
e8878e5ce8
2 changed files with 34 additions and 0 deletions
internal_packages/message-list
|
@ -7,4 +7,10 @@ class AutolinkerExtension extends MessageStoreExtension
|
||||||
# Apply the autolinker pass to make emails and links clickable
|
# Apply the autolinker pass to make emails and links clickable
|
||||||
message.body = Autolinker.link(message.body, {twitter: false})
|
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
|
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…
Add table
Reference in a new issue