Upgrade linkifyjs to v4

This commit is contained in:
Simon Ser 2024-01-10 11:33:20 +01:00
parent 67b2b07506
commit 0640ff8712
4 changed files with 28 additions and 32 deletions

View file

@ -4,5 +4,5 @@ import { h } from "../node_modules/preact/dist/preact.module.js";
import htm from "../node_modules/htm/dist/htm.module.js";
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 };

View file

@ -5,35 +5,31 @@ linkifyjs.options.defaults.defaultProtocol = "https";
linkifyjs.registerCustomProtocol("irc");
linkifyjs.registerCustomProtocol("ircs");
linkifyjs.registerPlugin("ircChannel", ({ scanner, parser, utils }) => {
const { POUND, DOMAIN, TLD, LOCALHOST, UNDERSCORE, DOT, HYPHEN } = scanner.tokens;
const START_STATE = parser.start;
const Channel = utils.createTokenClass("ircChannel", {
const IRCChannelToken = linkifyjs.createTokenClass("ircChannel", {
isLink: true,
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);
HASH_STATE.tt(TLD, CHAN_STATE);
HASH_STATE.tt(LOCALHOST, CHAN_STATE);
HASH_STATE.tt(POUND, CHAN_STATE);
const Prefix = parser.start.tt(POUND);
const Channel = new linkifyjs.State(IRCChannelToken);
const Divider = Channel.tt(DOT);
CHAN_STATE.tt(UNDERSCORE, CHAN_STATE);
CHAN_STATE.tt(DOMAIN, CHAN_STATE);
CHAN_STATE.tt(TLD, CHAN_STATE);
CHAN_STATE.tt(LOCALHOST, CHAN_STATE);
const CHAN_DIVIDER_STATE = CHAN_STATE.tt(DOT);
CHAN_DIVIDER_STATE.tt(UNDERSCORE, CHAN_STATE);
CHAN_DIVIDER_STATE.tt(DOMAIN, CHAN_STATE);
CHAN_DIVIDER_STATE.tt(TLD, CHAN_STATE);
CHAN_DIVIDER_STATE.tt(LOCALHOST, CHAN_STATE);
Prefix.ta(alphanumeric, Channel);
Prefix.tt(POUND, Channel);
Prefix.tt(UNDERSCORE, Channel);
Prefix.tt(DOT, Divider);
Prefix.tt(HYPHEN, Channel);
Channel.ta(alphanumeric, Channel);
Channel.tt(POUND, Channel);
Channel.tt(UNDERSCORE, Channel);
Channel.tt(HYPHEN, Channel);
Divider.ta(alphanumeric, Channel);
});
export default function linkify(text, onClick) {

8
package-lock.json generated
View file

@ -7,7 +7,7 @@
"name": "gamja",
"dependencies": {
"htm": "^3.0.4",
"linkifyjs": "^3.0.2",
"linkifyjs": "^4.1.3",
"preact": "^10.5.9"
},
"devDependencies": {
@ -3080,9 +3080,9 @@
"dev": true
},
"node_modules/linkifyjs": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-3.0.5.tgz",
"integrity": "sha512-1Y9XQH65eQKA9p2xtk+zxvnTeQBG7rdAXSkUG97DmuI/Xhji9uaUzaWxRj6rf9YC0v8KKHkxav7tnLX82Sz5Fg=="
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-4.1.3.tgz",
"integrity": "sha512-auMesunaJ8yfkHvK4gfg1K0SaKX/6Wn9g2Aac/NwX+l5VdmFZzo/hdPGxEOETj+ryRa4/fiOPjeeKURSAJx1sg=="
},
"node_modules/lmdb": {
"version": "2.8.5",

View file

@ -3,7 +3,7 @@
"type": "module",
"dependencies": {
"htm": "^3.0.4",
"linkifyjs": "^3.0.2",
"linkifyjs": "^4.1.3",
"preact": "^10.5.9"
},
"devDependencies": {