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;
|
isLink: true,
|
||||||
const START_STATE = parser.start;
|
toHref() {
|
||||||
|
return "irc:///" + this.v;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const Channel = utils.createTokenClass("ircChannel", {
|
linkifyjs.registerPlugin("ircChannel", ({ scanner, parser }) => {
|
||||||
isLink: true,
|
const { POUND, UNDERSCORE, DOT, HYPHEN } = scanner.tokens;
|
||||||
toHref() {
|
const { alphanumeric } = scanner.tokens.groups;
|
||||||
return "irc:///" + this.toString();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const HASH_STATE = START_STATE.tt(POUND);
|
const Prefix = parser.start.tt(POUND);
|
||||||
|
const Channel = new linkifyjs.State(IRCChannelToken);
|
||||||
|
const Divider = Channel.tt(DOT);
|
||||||
|
|
||||||
const CHAN_STATE = HASH_STATE.tt(DOMAIN, Channel);
|
Prefix.ta(alphanumeric, Channel);
|
||||||
HASH_STATE.tt(TLD, CHAN_STATE);
|
Prefix.tt(POUND, Channel);
|
||||||
HASH_STATE.tt(LOCALHOST, CHAN_STATE);
|
Prefix.tt(UNDERSCORE, Channel);
|
||||||
HASH_STATE.tt(POUND, CHAN_STATE);
|
Prefix.tt(DOT, Divider);
|
||||||
|
Prefix.tt(HYPHEN, Channel);
|
||||||
CHAN_STATE.tt(UNDERSCORE, CHAN_STATE);
|
Channel.ta(alphanumeric, Channel);
|
||||||
CHAN_STATE.tt(DOMAIN, CHAN_STATE);
|
Channel.tt(POUND, Channel);
|
||||||
CHAN_STATE.tt(TLD, CHAN_STATE);
|
Channel.tt(UNDERSCORE, Channel);
|
||||||
CHAN_STATE.tt(LOCALHOST, CHAN_STATE);
|
Channel.tt(HYPHEN, Channel);
|
||||||
|
Divider.ta(alphanumeric, Channel);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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