UNPKG

koishi-plugin-booru-pixiv

Version:
31 lines (30 loc) 1.56 kB
import { jsx as _jsx, Fragment as _Fragment } from "@satorijs/element/jsx-runtime"; /* eslint-disable brace-style */ import { h } from 'koishi'; export function normaliseCaption(caption) { if (!caption?.trim()) { return _jsx("text", {}); } return (_jsx(_Fragment, { children: h.transform(h.parse(caption), { a(attrs) { let url = (attrs['href'] || ''); if (url) { let m = null; // Convert pixiv://users/1234 to https://www.pixiv.net/u/1234 if (((m = /pixiv:\/\/users\/(?<id>\d+)/.exec(url)), m?.groups?.id)) { url = `https://www.pixiv.net/u/${m.groups.id}`; } // Convert pixiv://illusts/1234 to https://www.pixiv.net/i/1234 else if (((m = /pixiv:\/\/illusts\/(?<id>\d+)/.exec(url)), m?.groups?.id)) { url = `https://www.pixiv.net/i/${m.groups.id}`; } // Convert pixiv://novels/1234 to https://www.pixiv.net/novel/show.php?id=1234 else if (((m = /pixiv:\/\/novels\/(?<id>\d+)/.exec(url)), m?.groups?.id)) { url = `https://www.pixiv.net/novel/show.php?id=${m.groups.id}`; } // There are also `twitter/` link, since its href is just a valid URL, we don't need to handle it } return _jsx("a", { href: url, children: attrs.children || [] }); }, }) })); }