2023-07-27 05:31:52 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-12-25 09:03:06 +00:00
|
|
|
import { VNode, h, SetupContext } from 'vue';
|
2021-04-02 01:36:11 +00:00
|
|
|
import * as mfm from 'mfm-js';
|
2023-05-14 03:23:39 +00:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-08-30 15:24:33 +00:00
|
|
|
import MkUrl from '@/components/global/MkUrl.vue';
|
2023-11-17 06:05:37 +00:00
|
|
|
import MkTime from '@/components/global/MkTime.vue';
|
2022-08-30 15:24:33 +00:00
|
|
|
import MkLink from '@/components/MkLink.vue';
|
|
|
|
import MkMention from '@/components/MkMention.vue';
|
|
|
|
import MkEmoji from '@/components/global/MkEmoji.vue';
|
2023-01-26 06:48:12 +00:00
|
|
|
import MkCustomEmoji from '@/components/global/MkCustomEmoji.vue';
|
2022-08-30 15:24:33 +00:00
|
|
|
import MkCode from '@/components/MkCode.vue';
|
|
|
|
import MkGoogle from '@/components/MkGoogle.vue';
|
|
|
|
import MkSparkle from '@/components/MkSparkle.vue';
|
|
|
|
import MkA from '@/components/global/MkA.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { host } from '@/config.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2023-10-28 03:41:17 +00:00
|
|
|
import { nyaize as doNyaize } from '@/scripts/nyaize.js';
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-01-14 03:43:54 +00:00
|
|
|
const QUOTE_STYLE = `
|
|
|
|
display: block;
|
|
|
|
margin: 8px;
|
|
|
|
padding: 6px 0 6px 12px;
|
|
|
|
color: var(--fg);
|
|
|
|
border-left: solid 3px var(--fg);
|
|
|
|
opacity: 0.7;
|
|
|
|
`.split('\n').join(' ');
|
|
|
|
|
2023-10-28 03:41:17 +00:00
|
|
|
type MfmProps = {
|
2023-05-14 03:23:39 +00:00
|
|
|
text: string;
|
|
|
|
plain?: boolean;
|
|
|
|
nowrap?: boolean;
|
|
|
|
author?: Misskey.entities.UserLite;
|
|
|
|
isNote?: boolean;
|
|
|
|
emojiUrls?: string[];
|
|
|
|
rootScale?: number;
|
2023-12-14 04:11:23 +00:00
|
|
|
nyaize?: boolean | 'respect';
|
2023-11-01 01:23:20 +00:00
|
|
|
parsedNodes?: mfm.MfmNode[] | null;
|
2023-11-04 09:27:22 +00:00
|
|
|
enableEmojiMenu?: boolean;
|
|
|
|
enableEmojiMenuReaction?: boolean;
|
2023-10-28 03:41:17 +00:00
|
|
|
};
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-12-25 09:03:06 +00:00
|
|
|
type MfmEvents = {
|
|
|
|
clickEv(id: string): void;
|
|
|
|
};
|
|
|
|
|
2023-10-28 03:41:17 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2023-12-25 09:03:06 +00:00
|
|
|
export default function(props: MfmProps, context: SetupContext<MfmEvents>) {
|
2023-10-28 03:41:17 +00:00
|
|
|
const isNote = props.isNote ?? true;
|
2023-11-15 02:09:54 +00:00
|
|
|
const shouldNyaize = props.nyaize ? props.nyaize === 'respect' ? props.author?.isCat : false : false;
|
2023-10-28 03:41:17 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
2023-05-14 03:23:39 +00:00
|
|
|
if (props.text == null || props.text === '') return;
|
2018-11-20 20:11:00 +00:00
|
|
|
|
2023-11-01 01:23:20 +00:00
|
|
|
const rootAst = props.parsedNodes ?? (props.plain ? mfm.parseSimple : mfm.parse)(props.text);
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
const validTime = (t: string | null | undefined) => {
|
|
|
|
if (t == null) return null;
|
|
|
|
return t.match(/^[0-9.]+s$/) ? t : null;
|
|
|
|
};
|
2024-01-13 12:17:00 +00:00
|
|
|
|
|
|
|
const validColor = (c: string | null | undefined): string | null => {
|
|
|
|
if (c == null) return null;
|
|
|
|
return c.match(/^[0-9a-f]{3,6}$/i) ? c : null;
|
|
|
|
};
|
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
const useAnim = defaultStore.state.advancedMfm && defaultStore.state.animatedMfm;
|
2023-02-11 02:31:18 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
/**
|
|
|
|
* Gen Vue Elements from MFM AST
|
|
|
|
* @param ast MFM AST
|
|
|
|
* @param scale How times large the text is
|
2023-10-28 03:41:17 +00:00
|
|
|
* @param disableNyaize Whether nyaize is disabled or not
|
2023-05-14 03:23:39 +00:00
|
|
|
*/
|
2023-10-19 02:42:17 +00:00
|
|
|
const genEl = (ast: mfm.MfmNode[], scale: number, disableNyaize = false) => ast.map((token): VNode | string | (VNode | string)[] => {
|
2023-05-14 03:23:39 +00:00
|
|
|
switch (token.type) {
|
|
|
|
case 'text': {
|
2023-10-19 02:42:17 +00:00
|
|
|
let text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n');
|
2023-10-28 03:41:17 +00:00
|
|
|
if (!disableNyaize && shouldNyaize) {
|
|
|
|
text = doNyaize(text);
|
2023-10-19 02:42:17 +00:00
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
if (!props.plain) {
|
|
|
|
const res: (VNode | string)[] = [];
|
|
|
|
for (const t of text.split('\n')) {
|
|
|
|
res.push(h('br'));
|
|
|
|
res.push(t);
|
2018-03-31 12:41:08 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
res.shift();
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
return [text.replace(/\n/g, ' ')];
|
2018-08-05 10:20:26 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'bold': {
|
|
|
|
return [h('b', genEl(token.children, scale))];
|
|
|
|
}
|
2018-08-03 14:27:37 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'strike': {
|
|
|
|
return [h('del', genEl(token.children, scale))];
|
|
|
|
}
|
2018-12-03 16:28:21 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'italic': {
|
|
|
|
return h('i', {
|
|
|
|
style: 'font-style: oblique;',
|
|
|
|
}, genEl(token.children, scale));
|
|
|
|
}
|
2018-12-05 08:39:26 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'fn': {
|
|
|
|
// TODO: CSSを文字列で組み立てていくと token.props.args.~~~ 経由でCSSインジェクションできるのでよしなにやる
|
2023-11-30 05:46:16 +00:00
|
|
|
let style: string | undefined;
|
2023-05-14 03:23:39 +00:00
|
|
|
switch (token.props.name) {
|
|
|
|
case 'tada': {
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = 'font-size: 150%;' + (useAnim ? `animation: tada ${speed} linear infinite both; animation-delay: ${delay};` : '');
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'jelly': {
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = (useAnim ? `animation: mfm-rubberBand ${speed} linear infinite both; animation-delay: ${delay};` : '');
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'twitch': {
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.5s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = useAnim ? `animation: mfm-twitch ${speed} ease infinite; animation-delay: ${delay};` : '';
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'shake': {
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.5s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = useAnim ? `animation: mfm-shake ${speed} ease infinite; animation-delay: ${delay};` : '';
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'spin': {
|
|
|
|
const direction =
|
|
|
|
token.props.args.left ? 'reverse' :
|
|
|
|
token.props.args.alternate ? 'alternate' :
|
|
|
|
'normal';
|
|
|
|
const anime =
|
|
|
|
token.props.args.x ? 'mfm-spinX' :
|
|
|
|
token.props.args.y ? 'mfm-spinY' :
|
|
|
|
'mfm-spin';
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1.5s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = useAnim ? `animation: ${anime} ${speed} linear infinite; animation-direction: ${direction}; animation-delay: ${delay};` : '';
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'jump': {
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.75s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = useAnim ? `animation: mfm-jump ${speed} linear infinite; animation-delay: ${delay};` : '';
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'bounce': {
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.75s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = useAnim ? `animation: mfm-bounce ${speed} linear infinite; transform-origin: center bottom; animation-delay: ${delay};` : '';
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'flip': {
|
|
|
|
const transform =
|
|
|
|
(token.props.args.h && token.props.args.v) ? 'scale(-1, -1)' :
|
|
|
|
token.props.args.v ? 'scaleY(-1)' :
|
|
|
|
'scaleX(-1)';
|
|
|
|
style = `transform: ${transform};`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'x2': {
|
|
|
|
return h('span', {
|
|
|
|
class: defaultStore.state.advancedMfm ? 'mfm-x2' : '',
|
|
|
|
}, genEl(token.children, scale * 2));
|
|
|
|
}
|
|
|
|
case 'x3': {
|
|
|
|
return h('span', {
|
|
|
|
class: defaultStore.state.advancedMfm ? 'mfm-x3' : '',
|
|
|
|
}, genEl(token.children, scale * 3));
|
|
|
|
}
|
|
|
|
case 'x4': {
|
|
|
|
return h('span', {
|
|
|
|
class: defaultStore.state.advancedMfm ? 'mfm-x4' : '',
|
|
|
|
}, genEl(token.children, scale * 4));
|
|
|
|
}
|
|
|
|
case 'font': {
|
|
|
|
const family =
|
|
|
|
token.props.args.serif ? 'serif' :
|
|
|
|
token.props.args.monospace ? 'monospace' :
|
|
|
|
token.props.args.cursive ? 'cursive' :
|
|
|
|
token.props.args.fantasy ? 'fantasy' :
|
|
|
|
token.props.args.emoji ? 'emoji' :
|
|
|
|
token.props.args.math ? 'math' :
|
|
|
|
null;
|
|
|
|
if (family) style = `font-family: ${family};`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'blur': {
|
|
|
|
return h('span', {
|
|
|
|
class: '_mfm_blur_',
|
|
|
|
}, genEl(token.children, scale));
|
|
|
|
}
|
|
|
|
case 'rainbow': {
|
2023-08-21 11:24:18 +00:00
|
|
|
if (!useAnim) {
|
|
|
|
return h('span', {
|
|
|
|
class: '_mfm_rainbow_fallback_',
|
|
|
|
}, genEl(token.children, scale));
|
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
2023-12-14 08:57:57 +00:00
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
style = `animation: mfm-rainbow ${speed} linear infinite; animation-delay: ${delay};`;
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'sparkle': {
|
|
|
|
if (!useAnim) {
|
|
|
|
return genEl(token.children, scale);
|
2023-01-13 23:52:32 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
return h(MkSparkle, {}, genEl(token.children, scale));
|
|
|
|
}
|
|
|
|
case 'rotate': {
|
|
|
|
const degrees = parseFloat(token.props.args.deg ?? '90');
|
|
|
|
style = `transform: rotate(${degrees}deg); transform-origin: center center;`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'position': {
|
|
|
|
if (!defaultStore.state.advancedMfm) break;
|
|
|
|
const x = parseFloat(token.props.args.x ?? '0');
|
|
|
|
const y = parseFloat(token.props.args.y ?? '0');
|
|
|
|
style = `transform: translateX(${x}em) translateY(${y}em);`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'scale': {
|
|
|
|
if (!defaultStore.state.advancedMfm) {
|
|
|
|
style = '';
|
2023-01-13 23:52:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
const x = Math.min(parseFloat(token.props.args.x ?? '1'), 5);
|
|
|
|
const y = Math.min(parseFloat(token.props.args.y ?? '1'), 5);
|
2023-07-07 22:08:16 +00:00
|
|
|
style = `transform: scale(${x}, ${y});`;
|
2023-05-14 03:23:39 +00:00
|
|
|
scale = scale * Math.max(x, y);
|
|
|
|
break;
|
2020-11-07 14:41:21 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'fg': {
|
2024-01-13 12:17:00 +00:00
|
|
|
let color = validColor(token.props.args.color);
|
|
|
|
color = color ?? 'f00';
|
2023-12-27 11:41:01 +00:00
|
|
|
style = `color: #${color}; overflow-wrap: anywhere;`;
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'bg': {
|
2024-01-13 12:17:00 +00:00
|
|
|
let color = validColor(token.props.args.color);
|
|
|
|
color = color ?? 'f00';
|
2023-12-27 11:41:01 +00:00
|
|
|
style = `background-color: #${color}; overflow-wrap: anywhere;`;
|
2023-05-14 03:23:39 +00:00
|
|
|
break;
|
2020-11-09 13:32:01 +00:00
|
|
|
}
|
2024-01-13 12:17:00 +00:00
|
|
|
case 'border': {
|
|
|
|
let color = validColor(token.props.args.color);
|
|
|
|
color = color ? `#${color}` : 'var(--accent)';
|
|
|
|
let b_style = token.props.args.style;
|
|
|
|
if (
|
|
|
|
!['hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset']
|
|
|
|
.includes(b_style)
|
|
|
|
) b_style = 'solid';
|
|
|
|
const width = parseFloat(token.props.args.width ?? '1');
|
|
|
|
const radius = parseFloat(token.props.args.radius ?? '0');
|
|
|
|
style = `border: ${width}px ${b_style} ${color}; border-radius: ${radius}px`;
|
|
|
|
break;
|
|
|
|
}
|
2023-11-17 04:09:56 +00:00
|
|
|
case 'ruby': {
|
2023-11-17 04:20:40 +00:00
|
|
|
if (token.children.length === 1) {
|
|
|
|
const child = token.children[0];
|
2023-12-02 08:09:22 +00:00
|
|
|
let text = child.type === 'text' ? child.props.text : '';
|
|
|
|
if (!disableNyaize && shouldNyaize) {
|
|
|
|
text = doNyaize(text);
|
|
|
|
}
|
2023-11-17 04:20:40 +00:00
|
|
|
return h('ruby', {}, [text.split(' ')[0], h('rt', text.split(' ')[1])]);
|
|
|
|
} else {
|
|
|
|
const rt = token.children.at(-1)!;
|
2023-12-02 08:09:22 +00:00
|
|
|
let text = rt.type === 'text' ? rt.props.text : '';
|
|
|
|
if (!disableNyaize && shouldNyaize) {
|
|
|
|
text = doNyaize(text);
|
|
|
|
}
|
2023-11-17 04:20:40 +00:00
|
|
|
return h('ruby', {}, [...genEl(token.children.slice(0, token.children.length - 1), scale), h('rt', text.trim())]);
|
|
|
|
}
|
2023-11-17 04:09:56 +00:00
|
|
|
}
|
2023-11-17 06:05:37 +00:00
|
|
|
case 'unixtime': {
|
|
|
|
const child = token.children[0];
|
|
|
|
const unixtime = parseInt(child.type === 'text' ? child.props.text : '');
|
|
|
|
return h('span', {
|
|
|
|
style: 'display: inline-block; font-size: 90%; border: solid 1px var(--divider); border-radius: 999px; padding: 4px 10px 4px 6px;',
|
|
|
|
}, [
|
|
|
|
h('i', {
|
|
|
|
class: 'ti ti-clock',
|
|
|
|
style: 'margin-right: 0.25em;',
|
|
|
|
}),
|
2023-11-17 06:33:57 +00:00
|
|
|
h(MkTime, {
|
|
|
|
key: Math.random(),
|
|
|
|
time: unixtime * 1000,
|
|
|
|
mode: 'detail',
|
|
|
|
}),
|
2023-11-17 06:05:37 +00:00
|
|
|
]);
|
|
|
|
}
|
2023-12-25 09:03:06 +00:00
|
|
|
case 'clickable': {
|
|
|
|
return h('span', { onClick(ev: MouseEvent): void {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
context.emit('clickEv', token.props.args.ev ?? '');
|
|
|
|
} }, genEl(token.children, scale));
|
|
|
|
}
|
2018-08-05 10:20:26 +00:00
|
|
|
}
|
2023-11-30 05:46:16 +00:00
|
|
|
if (style === undefined) {
|
2023-05-14 03:23:39 +00:00
|
|
|
return h('span', {}, ['$[', token.props.name, ' ', ...genEl(token.children, scale), ']']);
|
|
|
|
} else {
|
|
|
|
return h('span', {
|
|
|
|
style: 'display: inline-block; ' + style,
|
|
|
|
}, genEl(token.children, scale));
|
2018-12-05 11:11:54 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
2018-12-05 11:11:54 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'small': {
|
|
|
|
return [h('small', {
|
|
|
|
style: 'opacity: 0.7;',
|
|
|
|
}, genEl(token.children, scale))];
|
|
|
|
}
|
2018-11-25 04:36:40 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'center': {
|
|
|
|
return [h('div', {
|
|
|
|
style: 'text-align:center;',
|
|
|
|
}, genEl(token.children, scale))];
|
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'url': {
|
|
|
|
return [h(MkUrl, {
|
|
|
|
key: Math.random(),
|
|
|
|
url: token.props.url,
|
|
|
|
rel: 'nofollow noopener',
|
|
|
|
})];
|
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'link': {
|
|
|
|
return [h(MkLink, {
|
|
|
|
key: Math.random(),
|
|
|
|
url: token.props.url,
|
|
|
|
rel: 'nofollow noopener',
|
2023-10-19 02:42:17 +00:00
|
|
|
}, genEl(token.children, scale, true))];
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'mention': {
|
|
|
|
return [h(MkMention, {
|
|
|
|
key: Math.random(),
|
2023-07-16 05:21:05 +00:00
|
|
|
host: (token.props.host == null && props.author && props.author.host != null ? props.author.host : token.props.host) ?? host,
|
2023-05-14 03:23:39 +00:00
|
|
|
username: token.props.username,
|
|
|
|
})];
|
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'hashtag': {
|
|
|
|
return [h(MkA, {
|
|
|
|
key: Math.random(),
|
|
|
|
to: isNote ? `/tags/${encodeURIComponent(token.props.hashtag)}` : `/user-tags/${encodeURIComponent(token.props.hashtag)}`,
|
|
|
|
style: 'color:var(--hashtag);',
|
|
|
|
}, `#${token.props.hashtag}`)];
|
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'blockCode': {
|
|
|
|
return [h(MkCode, {
|
|
|
|
key: Math.random(),
|
|
|
|
code: token.props.code,
|
|
|
|
lang: token.props.lang,
|
|
|
|
})];
|
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'inlineCode': {
|
|
|
|
return [h(MkCode, {
|
|
|
|
key: Math.random(),
|
|
|
|
code: token.props.code,
|
|
|
|
inline: true,
|
|
|
|
})];
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'quote': {
|
|
|
|
if (!props.nowrap) {
|
|
|
|
return [h('div', {
|
|
|
|
style: QUOTE_STYLE,
|
2023-10-19 02:42:17 +00:00
|
|
|
}, genEl(token.children, scale, true))];
|
2023-05-14 03:23:39 +00:00
|
|
|
} else {
|
|
|
|
return [h('span', {
|
|
|
|
style: QUOTE_STYLE,
|
2023-10-19 02:42:17 +00:00
|
|
|
}, genEl(token.children, scale, true))];
|
2018-08-05 10:20:26 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'emojiCode': {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
if (props.author?.host == null) {
|
|
|
|
return [h(MkCustomEmoji, {
|
|
|
|
key: Math.random(),
|
|
|
|
name: token.props.name,
|
|
|
|
normal: props.plain,
|
|
|
|
host: null,
|
|
|
|
useOriginalSize: scale >= 2.5,
|
2023-11-04 09:27:22 +00:00
|
|
|
menu: props.enableEmojiMenu,
|
|
|
|
menuReaction: props.enableEmojiMenuReaction,
|
2023-05-14 03:23:39 +00:00
|
|
|
})];
|
|
|
|
} else {
|
2023-01-26 06:48:12 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
2023-05-14 03:23:39 +00:00
|
|
|
if (props.emojiUrls && (props.emojiUrls[token.props.name] == null)) {
|
|
|
|
return [h('span', `:${token.props.name}:`)];
|
|
|
|
} else {
|
2023-01-26 06:48:12 +00:00
|
|
|
return [h(MkCustomEmoji, {
|
|
|
|
key: Math.random(),
|
|
|
|
name: token.props.name,
|
2023-05-14 03:23:39 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
url: props.emojiUrls ? props.emojiUrls[token.props.name] : null,
|
|
|
|
normal: props.plain,
|
|
|
|
host: props.author.host,
|
2023-04-12 01:58:56 +00:00
|
|
|
useOriginalSize: scale >= 2.5,
|
2023-01-26 06:48:12 +00:00
|
|
|
})];
|
|
|
|
}
|
2021-04-02 01:36:11 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
2021-04-02 01:36:11 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'unicodeEmoji': {
|
|
|
|
return [h(MkEmoji, {
|
|
|
|
key: Math.random(),
|
|
|
|
emoji: token.props.emoji,
|
2023-11-05 09:01:51 +00:00
|
|
|
menu: props.enableEmojiMenu,
|
|
|
|
menuReaction: props.enableEmojiMenuReaction,
|
2023-05-14 03:23:39 +00:00
|
|
|
})];
|
|
|
|
}
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'mathInline': {
|
|
|
|
return [h('code', token.props.formula)];
|
|
|
|
}
|
2019-01-25 14:08:06 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'mathBlock': {
|
|
|
|
return [h('code', token.props.formula)];
|
|
|
|
}
|
2018-11-16 08:03:52 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'search': {
|
|
|
|
return [h(MkGoogle, {
|
|
|
|
key: Math.random(),
|
|
|
|
q: token.props.query,
|
|
|
|
})];
|
|
|
|
}
|
2018-04-21 09:59:16 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
case 'plain': {
|
2023-10-19 02:42:17 +00:00
|
|
|
return [h('span', genEl(token.children, scale, true))];
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
2022-07-12 03:03:38 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
default: {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
console.error('unrecognized ast type:', (token as any).type);
|
2018-09-11 18:32:47 +00:00
|
|
|
|
2023-05-14 03:23:39 +00:00
|
|
|
return [];
|
2018-03-31 12:41:08 +00:00
|
|
|
}
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|
|
|
|
}).flat(Infinity) as (VNode | string)[];
|
2018-03-31 12:41:08 +00:00
|
|
|
|
2023-05-17 02:50:37 +00:00
|
|
|
return h('span', {
|
|
|
|
// https://codeday.me/jp/qa/20190424/690106.html
|
|
|
|
style: props.nowrap ? 'white-space: pre; word-wrap: normal; overflow: hidden; text-overflow: ellipsis;' : 'white-space: pre-wrap;',
|
2023-10-28 03:41:17 +00:00
|
|
|
}, genEl(rootAst, props.rootScale ?? 1));
|
2023-05-14 03:23:39 +00:00
|
|
|
}
|