You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-05 23:10:41 +03:00
linkify vector.im URLs directly into the app, both from HTML and non-HTML messages
This commit is contained in:
@@ -19,6 +19,7 @@ limitations under the License.
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
var sanitizeHtml = require('sanitize-html');
|
var sanitizeHtml = require('sanitize-html');
|
||||||
var highlight = require('highlight.js');
|
var highlight = require('highlight.js');
|
||||||
|
var linkifyMatrix = require('./linkify-matrix');
|
||||||
|
|
||||||
var sanitizeHtmlParams = {
|
var sanitizeHtmlParams = {
|
||||||
allowedTags: [
|
allowedTags: [
|
||||||
@@ -44,8 +45,17 @@ var sanitizeHtmlParams = {
|
|||||||
allowedSchemesByTag: {},
|
allowedSchemesByTag: {},
|
||||||
|
|
||||||
transformTags: { // custom to matrix
|
transformTags: { // custom to matrix
|
||||||
// add blank targets to all hyperlinks
|
// add blank targets to all hyperlinks except vector URLs
|
||||||
'a': sanitizeHtml.simpleTransform('a', { target: '_blank'} )
|
'a': function(tagName, attribs) {
|
||||||
|
// XXX: use matrix.to instead and deduplicate regexp with linkify-matrix.js
|
||||||
|
var m = attribs.href.match(linkifyMatrix.VECTOR_URL_PATTERN);
|
||||||
|
if (m) {
|
||||||
|
return { tagName: 'a', attribs: { href: m[4] } };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return { tagName: 'a', attribs: { href: attribs.href, target: '_blank'} };
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ function matrixLinkify(linkify) {
|
|||||||
matrixLinkify.onUserClick = function(e, userId) { e.preventDefault(); };
|
matrixLinkify.onUserClick = function(e, userId) { e.preventDefault(); };
|
||||||
matrixLinkify.onAliasClick = function(e, roomAlias) { e.preventDefault(); };
|
matrixLinkify.onAliasClick = function(e, roomAlias) { e.preventDefault(); };
|
||||||
|
|
||||||
|
matrixLinkify.VECTOR_URL_PATTERN = /(https?:\/\/)?(www\.)?vector\.im\/(beta|staging|develop)?\/(#.*)/;
|
||||||
|
|
||||||
matrixLinkify.options = {
|
matrixLinkify.options = {
|
||||||
events: function (href, type) {
|
events: function (href, type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -122,10 +124,29 @@ matrixLinkify.options = {
|
|||||||
return '#/room/' + href;
|
return '#/room/' + href;
|
||||||
case 'userid':
|
case 'userid':
|
||||||
return '#';
|
return '#';
|
||||||
|
case 'url':
|
||||||
|
// intercept vector links directly into the app
|
||||||
|
// FIXME: use matrix.to asap, as this is fragile as sin
|
||||||
|
var m = href.match(matrixLinkify.VECTOR_URL_PATTERN);
|
||||||
|
return m ? m[4] : href;
|
||||||
default:
|
default:
|
||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
target: function(href, type) {
|
||||||
|
if (type === 'url') {
|
||||||
|
if (href.match(matrixLinkify.VECTOR_URL_PATTERN)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return '_blank';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return '_blank';
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = matrixLinkify;
|
module.exports = matrixLinkify;
|
||||||
|
|||||||
Reference in New Issue
Block a user