mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
Upgrade linkifyjs to v4
This commit is contained in:
parent
67b2b07506
commit
0640ff8712
4 changed files with 28 additions and 32 deletions
|
@ -4,5 +4,5 @@ import { h } from "../node_modules/preact/dist/preact.module.js";
|
||||||
import htm from "../node_modules/htm/dist/htm.module.js";
|
import htm from "../node_modules/htm/dist/htm.module.js";
|
||||||
export const html = htm.bind(h);
|
export const html = htm.bind(h);
|
||||||
|
|
||||||
import * as linkifyjs from "../node_modules/linkifyjs/dist/linkify.module.js";
|
import * as linkifyjs from "../node_modules/linkifyjs/dist/linkify.es.js";
|
||||||
export { linkifyjs };
|
export { linkifyjs };
|
||||||
|
|
|
@ -5,35 +5,31 @@ linkifyjs.options.defaults.defaultProtocol = "https";
|
||||||
linkifyjs.registerCustomProtocol("irc");
|
linkifyjs.registerCustomProtocol("irc");
|
||||||
linkifyjs.registerCustomProtocol("ircs");
|
linkifyjs.registerCustomProtocol("ircs");
|
||||||
|
|
||||||
linkifyjs.registerPlugin("ircChannel", ({ scanner, parser, utils }) => {
|
const IRCChannelToken = linkifyjs.createTokenClass("ircChannel", {
|
||||||
const { POUND, DOMAIN, TLD, LOCALHOST, UNDERSCORE, DOT, HYPHEN } = scanner.tokens;
|
|
||||||
const START_STATE = parser.start;
|
|
||||||
|
|
||||||
const Channel = utils.createTokenClass("ircChannel", {
|
|
||||||
isLink: true,
|
isLink: true,
|
||||||
toHref() {
|
toHref() {
|
||||||
return "irc:///" + this.toString();
|
return "irc:///" + this.v;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const HASH_STATE = START_STATE.tt(POUND);
|
linkifyjs.registerPlugin("ircChannel", ({ scanner, parser }) => {
|
||||||
|
const { POUND, UNDERSCORE, DOT, HYPHEN } = scanner.tokens;
|
||||||
|
const { alphanumeric } = scanner.tokens.groups;
|
||||||
|
|
||||||
const CHAN_STATE = HASH_STATE.tt(DOMAIN, Channel);
|
const Prefix = parser.start.tt(POUND);
|
||||||
HASH_STATE.tt(TLD, CHAN_STATE);
|
const Channel = new linkifyjs.State(IRCChannelToken);
|
||||||
HASH_STATE.tt(LOCALHOST, CHAN_STATE);
|
const Divider = Channel.tt(DOT);
|
||||||
HASH_STATE.tt(POUND, CHAN_STATE);
|
|
||||||
|
|
||||||
CHAN_STATE.tt(UNDERSCORE, CHAN_STATE);
|
Prefix.ta(alphanumeric, Channel);
|
||||||
CHAN_STATE.tt(DOMAIN, CHAN_STATE);
|
Prefix.tt(POUND, Channel);
|
||||||
CHAN_STATE.tt(TLD, CHAN_STATE);
|
Prefix.tt(UNDERSCORE, Channel);
|
||||||
CHAN_STATE.tt(LOCALHOST, CHAN_STATE);
|
Prefix.tt(DOT, Divider);
|
||||||
|
Prefix.tt(HYPHEN, Channel);
|
||||||
const CHAN_DIVIDER_STATE = CHAN_STATE.tt(DOT);
|
Channel.ta(alphanumeric, Channel);
|
||||||
|
Channel.tt(POUND, Channel);
|
||||||
CHAN_DIVIDER_STATE.tt(UNDERSCORE, CHAN_STATE);
|
Channel.tt(UNDERSCORE, Channel);
|
||||||
CHAN_DIVIDER_STATE.tt(DOMAIN, CHAN_STATE);
|
Channel.tt(HYPHEN, Channel);
|
||||||
CHAN_DIVIDER_STATE.tt(TLD, CHAN_STATE);
|
Divider.ta(alphanumeric, Channel);
|
||||||
CHAN_DIVIDER_STATE.tt(LOCALHOST, CHAN_STATE);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function linkify(text, onClick) {
|
export default function linkify(text, onClick) {
|
||||||
|
|
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -7,7 +7,7 @@
|
||||||
"name": "gamja",
|
"name": "gamja",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"htm": "^3.0.4",
|
"htm": "^3.0.4",
|
||||||
"linkifyjs": "^3.0.2",
|
"linkifyjs": "^4.1.3",
|
||||||
"preact": "^10.5.9"
|
"preact": "^10.5.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -3080,9 +3080,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/linkifyjs": {
|
"node_modules/linkifyjs": {
|
||||||
"version": "3.0.5",
|
"version": "4.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-3.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-4.1.3.tgz",
|
||||||
"integrity": "sha512-1Y9XQH65eQKA9p2xtk+zxvnTeQBG7rdAXSkUG97DmuI/Xhji9uaUzaWxRj6rf9YC0v8KKHkxav7tnLX82Sz5Fg=="
|
"integrity": "sha512-auMesunaJ8yfkHvK4gfg1K0SaKX/6Wn9g2Aac/NwX+l5VdmFZzo/hdPGxEOETj+ryRa4/fiOPjeeKURSAJx1sg=="
|
||||||
},
|
},
|
||||||
"node_modules/lmdb": {
|
"node_modules/lmdb": {
|
||||||
"version": "2.8.5",
|
"version": "2.8.5",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"htm": "^3.0.4",
|
"htm": "^3.0.4",
|
||||||
"linkifyjs": "^3.0.2",
|
"linkifyjs": "^4.1.3",
|
||||||
"preact": "^10.5.9"
|
"preact": "^10.5.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Reference in a new issue