Fix linkification and bump linkifyjs dep
This commit is contained in:
parent
86da0e0d63
commit
8db2a4d46f
2 changed files with 35 additions and 27 deletions
|
@ -36,7 +36,7 @@
|
||||||
"fuse.js": "^2.2.0",
|
"fuse.js": "^2.2.0",
|
||||||
"glob": "^5.0.14",
|
"glob": "^5.0.14",
|
||||||
"highlight.js": "^8.9.1",
|
"highlight.js": "^8.9.1",
|
||||||
"linkifyjs": "2.0.0-beta.4",
|
"linkifyjs": "2.1.0",
|
||||||
"lodash": "^4.13.1",
|
"lodash": "^4.13.1",
|
||||||
"marked": "^0.3.5",
|
"marked": "^0.3.5",
|
||||||
"matrix-js-sdk": "matrix-org/matrix-js-sdk#develop",
|
"matrix-js-sdk": "matrix-org/matrix-js-sdk#develop",
|
||||||
|
|
|
@ -23,76 +23,84 @@ function matrixLinkify(linkify) {
|
||||||
var S_START = linkify.parser.start;
|
var S_START = linkify.parser.start;
|
||||||
|
|
||||||
|
|
||||||
var ROOMALIAS = function(value) {
|
function ROOMALIAS(value) {
|
||||||
MultiToken.call(this, value);
|
this.v = value;
|
||||||
this.type = 'roomalias';
|
}
|
||||||
this.isLink = true;
|
linkify.inherits(MultiToken, ROOMALIAS, {
|
||||||
};
|
type: 'roomalias',
|
||||||
ROOMALIAS.prototype = new MultiToken();
|
isLink: true,
|
||||||
|
});
|
||||||
|
|
||||||
var S_HASH = new linkify.parser.State();
|
var S_HASH = S_START.jump(TT.POUND);
|
||||||
var S_HASH_NAME = new linkify.parser.State();
|
var S_HASH_NAME = new linkify.parser.State();
|
||||||
var S_HASH_NAME_COLON = new linkify.parser.State();
|
var S_HASH_NAME_COLON = new linkify.parser.State();
|
||||||
var S_HASH_NAME_COLON_DOMAIN = new linkify.parser.State();
|
|
||||||
var S_HASH_NAME_COLON_DOMAIN_DOT = new linkify.parser.State();
|
|
||||||
var S_ROOMALIAS = new linkify.parser.State(ROOMALIAS);
|
var S_ROOMALIAS = new linkify.parser.State(ROOMALIAS);
|
||||||
|
|
||||||
|
// WTF!? It is absolutely crazy that these have to be listed out this way,
|
||||||
|
// TT.DOMAIN should've covered all of them!
|
||||||
|
|
||||||
|
const localpart_tokens = [
|
||||||
|
TT.DOMAIN,
|
||||||
|
TT.TLD,
|
||||||
|
TT.LOCALHOST,
|
||||||
|
TT.NUM,
|
||||||
|
TT.UNDERSCORE,
|
||||||
|
];
|
||||||
|
|
||||||
var roomname_tokens = [
|
var roomname_tokens = [
|
||||||
|
TT.POUND,
|
||||||
|
TT.UNDERSCORE,
|
||||||
TT.DOT,
|
TT.DOT,
|
||||||
TT.PLUS,
|
TT.PLUS,
|
||||||
TT.NUM,
|
TT.NUM,
|
||||||
TT.DOMAIN,
|
TT.DOMAIN,
|
||||||
TT.TLD
|
TT.LOCALHOST
|
||||||
];
|
];
|
||||||
|
|
||||||
S_START.on(TT.POUND, S_HASH);
|
S_START.on(TT.POUND, S_HASH);
|
||||||
|
|
||||||
S_HASH.on(roomname_tokens, S_HASH_NAME);
|
S_HASH.on(roomname_tokens, S_HASH_NAME);
|
||||||
S_HASH_NAME.on(roomname_tokens, S_HASH_NAME);
|
S_HASH_NAME.on(roomname_tokens, S_HASH_NAME);
|
||||||
S_HASH_NAME.on(TT.DOMAIN, S_HASH_NAME);
|
|
||||||
|
|
||||||
S_HASH_NAME.on(TT.COLON, S_HASH_NAME_COLON);
|
S_HASH_NAME.on(TT.COLON, S_HASH_NAME_COLON);
|
||||||
|
|
||||||
S_HASH_NAME_COLON.on(TT.DOMAIN, S_HASH_NAME_COLON_DOMAIN);
|
S_HASH_NAME_COLON.on(localpart_tokens, S_ROOMALIAS);
|
||||||
S_HASH_NAME_COLON_DOMAIN.on(TT.DOT, S_HASH_NAME_COLON_DOMAIN_DOT);
|
S_ROOMALIAS.on(TT.DOT, S_HASH_NAME_COLON);
|
||||||
S_HASH_NAME_COLON_DOMAIN_DOT.on(TT.DOMAIN, S_HASH_NAME_COLON_DOMAIN);
|
|
||||||
S_HASH_NAME_COLON_DOMAIN_DOT.on(TT.TLD, S_ROOMALIAS);
|
|
||||||
|
|
||||||
|
|
||||||
var USERID = function(value) {
|
var USERID = function(value) {
|
||||||
MultiToken.call(this, value);
|
this.v = value;
|
||||||
this.type = 'userid';
|
|
||||||
this.isLink = true;
|
|
||||||
};
|
};
|
||||||
USERID.prototype = new MultiToken();
|
linkify.inherits(MultiToken, USERID, {
|
||||||
|
type: 'userid',
|
||||||
|
isLink: true,
|
||||||
|
});
|
||||||
|
|
||||||
var S_AT = new linkify.parser.State();
|
var S_AT = new linkify.parser.State();
|
||||||
var S_AT_NAME = new linkify.parser.State();
|
var S_AT_NAME = new linkify.parser.State();
|
||||||
var S_AT_NAME_COLON = new linkify.parser.State();
|
var S_AT_NAME_COLON = new linkify.parser.State();
|
||||||
var S_AT_NAME_COLON_DOMAIN = new linkify.parser.State();
|
|
||||||
var S_AT_NAME_COLON_DOMAIN_DOT = new linkify.parser.State();
|
var S_AT_NAME_COLON_DOMAIN_DOT = new linkify.parser.State();
|
||||||
var S_USERID = new linkify.parser.State(USERID);
|
var S_USERID = new linkify.parser.State(USERID);
|
||||||
|
|
||||||
var username_tokens = [
|
var username_tokens = [
|
||||||
TT.DOT,
|
TT.DOT,
|
||||||
|
TT.UNDERSCORE,
|
||||||
TT.PLUS,
|
TT.PLUS,
|
||||||
TT.NUM,
|
TT.NUM,
|
||||||
TT.DOMAIN,
|
TT.DOMAIN,
|
||||||
TT.TLD
|
TT.TLD,
|
||||||
|
TT.LOCALHOST,
|
||||||
];
|
];
|
||||||
|
|
||||||
S_START.on(TT.AT, S_AT);
|
S_START.on(TT.AT, S_AT);
|
||||||
|
|
||||||
S_AT.on(username_tokens, S_AT_NAME);
|
S_AT.on(username_tokens, S_AT_NAME);
|
||||||
S_AT_NAME.on(username_tokens, S_AT_NAME);
|
S_AT_NAME.on(username_tokens, S_AT_NAME);
|
||||||
S_AT_NAME.on(TT.DOMAIN, S_AT_NAME);
|
|
||||||
|
|
||||||
S_AT_NAME.on(TT.COLON, S_AT_NAME_COLON);
|
S_AT_NAME.on(TT.COLON, S_AT_NAME_COLON);
|
||||||
|
|
||||||
S_AT_NAME_COLON.on(TT.DOMAIN, S_AT_NAME_COLON_DOMAIN);
|
S_AT_NAME_COLON.on(localpart_tokens, S_USERID);
|
||||||
S_AT_NAME_COLON_DOMAIN.on(TT.DOT, S_AT_NAME_COLON_DOMAIN_DOT);
|
S_USERID.on(TT.DOT, S_AT_NAME_COLON);
|
||||||
S_AT_NAME_COLON_DOMAIN_DOT.on(TT.DOMAIN, S_AT_NAME_COLON_DOMAIN);
|
|
||||||
S_AT_NAME_COLON_DOMAIN_DOT.on(TT.TLD, S_USERID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stubs, overwritten in MatrixChat's componentDidMount
|
// stubs, overwritten in MatrixChat's componentDidMount
|
||||||
|
|
Loading…
Reference in a new issue