mirror of
https://github.com/axllent/mailpit.git
synced 2025-07-17 01:32:33 +02:00
Feature: Convert links into clickable hyperlinks in plain text message content
@see 125
This commit is contained in:
@ -163,6 +163,27 @@ export default {
|
||||
self.scrollInPlace = true;
|
||||
self.$emit('loadMessages');
|
||||
});
|
||||
},
|
||||
|
||||
// Convert plain text to HTML including anchor links
|
||||
textToHTML: function (s) {
|
||||
// escape to HTML
|
||||
let html = s
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'")
|
||||
|
||||
// full links with http(s)
|
||||
let re = /(\b(https?|ftp):\/\/[\-\w@:%_\+.~#?,&\/\/=;]+)\b/gim
|
||||
html = html.replace(re, '<a href="$&" target="_blank" rel="noopener">$&</a>')
|
||||
|
||||
// plain www links without https?:// prefix
|
||||
let re2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim
|
||||
html = html.replace(re2, '$1<a href="http://$2" target="_blank" rel="noopener">$2</a>')
|
||||
|
||||
return html
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -317,7 +338,7 @@ export default {
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-plain-text" role="tabpanel" aria-labelledby="nav-plain-text-tab" tabindex="0"
|
||||
:class="message.HTML == '' ? 'show' : ''">
|
||||
<div class="text-view">{{ message.Text }}</div>
|
||||
<div class="text-view" v-html="textToHTML(message.Text)"></div>
|
||||
<Attachments v-if="allAttachments(message).length" :message="message"
|
||||
:attachments="allAttachments(message)"></Attachments>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user