Converge on permalink processing for HtmlUtils and linkify-matrix
This commit is contained in:
parent
ff4eee5239
commit
2cb0b4903a
3 changed files with 45 additions and 38 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2015, 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -15,6 +16,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import {baseUrl} from "./utils/permalinks/SpecPermalinkConstructor";
|
||||
import {tryTransformPermalinkToLocalHref} from "./utils/permalinks/RoomPermalinkCreator";
|
||||
|
||||
function matrixLinkify(linkify) {
|
||||
// Text tokens
|
||||
|
@ -225,20 +227,8 @@ matrixLinkify.options = {
|
|||
case 'roomalias':
|
||||
case 'userid':
|
||||
case 'groupid':
|
||||
return matrixLinkify.MATRIXTO_BASE_URL + '/#/' + href;
|
||||
default: {
|
||||
// FIXME: horrible duplication with HtmlUtils' transform tags
|
||||
let m = href.match(matrixLinkify.VECTOR_URL_PATTERN);
|
||||
if (m) {
|
||||
return m[1];
|
||||
}
|
||||
m = href.match(matrixLinkify.MATRIXTO_URL_PATTERN);
|
||||
if (m) {
|
||||
const entity = m[1];
|
||||
if (matrixToEntityMap[entity[0]]) return matrixToEntityMap[entity[0]] + entity;
|
||||
}
|
||||
|
||||
return href;
|
||||
return tryTransformPermalinkToLocalHref(href);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -249,8 +239,8 @@ matrixLinkify.options = {
|
|||
|
||||
target: function(href, type) {
|
||||
if (type === 'url') {
|
||||
if (href.match(matrixLinkify.VECTOR_URL_PATTERN) ||
|
||||
href.match(matrixLinkify.MATRIXTO_URL_PATTERN)) {
|
||||
const transformed = tryTransformPermalinkToLocalHref(href);
|
||||
if (transformed !== href || href.match(matrixLinkify.VECTOR_URL_PATTERN)) {
|
||||
return null;
|
||||
} else {
|
||||
return '_blank';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue