2023-01-13 13:40:33 +09:00
|
|
|
import { defineComponent, h } from "vue";
|
|
|
|
import * as mfm from "mfm-js";
|
|
|
|
import type { VNode } from "vue";
|
|
|
|
import MkUrl from "@/components/global/MkUrl.vue";
|
|
|
|
import MkLink from "@/components/MkLink.vue";
|
|
|
|
import MkMention from "@/components/MkMention.vue";
|
|
|
|
import MkEmoji from "@/components/global/MkEmoji.vue";
|
|
|
|
import { concat } from "@/scripts/array";
|
|
|
|
import MkFormula from "@/components/MkFormula.vue";
|
|
|
|
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";
|
|
|
|
import { host } from "@/config";
|
|
|
|
import { reducedMotion } from "@/scripts/reduced-motion";
|
2023-04-07 14:28:44 +09:00
|
|
|
import { defaultStore } from "@/store";
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2018-03-31 21:41:08 +09:00
|
|
|
props: {
|
|
|
|
text: {
|
|
|
|
type: String,
|
2022-06-23 21:46:15 +09:00
|
|
|
required: true,
|
2018-03-31 21:41:08 +09:00
|
|
|
},
|
2019-07-06 00:46:00 +09:00
|
|
|
plain: {
|
2018-03-31 21:41:08 +09:00
|
|
|
type: Boolean,
|
2022-06-23 21:46:15 +09:00
|
|
|
default: false,
|
2018-03-31 21:41:08 +09:00
|
|
|
},
|
2019-07-06 00:46:00 +09:00
|
|
|
nowrap: {
|
2018-12-06 10:02:04 +09:00
|
|
|
type: Boolean,
|
2022-06-23 21:46:15 +09:00
|
|
|
default: false,
|
2018-12-06 10:02:04 +09:00
|
|
|
},
|
2018-11-21 05:11:00 +09:00
|
|
|
author: {
|
|
|
|
type: Object,
|
2022-06-23 21:46:15 +09:00
|
|
|
default: null,
|
2018-11-21 05:11:00 +09:00
|
|
|
},
|
2018-03-31 21:41:08 +09:00
|
|
|
i: {
|
|
|
|
type: Object,
|
2022-06-23 21:46:15 +09:00
|
|
|
default: null,
|
2018-11-02 08:59:40 +09:00
|
|
|
},
|
|
|
|
customEmojis: {
|
|
|
|
required: false,
|
2019-02-17 23:41:47 +09:00
|
|
|
},
|
|
|
|
isNote: {
|
|
|
|
type: Boolean,
|
2022-06-23 21:46:15 +09:00
|
|
|
default: true,
|
2019-02-17 23:41:47 +09:00
|
|
|
},
|
2018-03-31 21:41:08 +09:00
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
render() {
|
2023-01-13 13:40:33 +09:00
|
|
|
if (this.text == null || this.text === "") return;
|
2018-11-21 05:11:00 +09:00
|
|
|
|
2023-04-10 14:42:17 +09:00
|
|
|
const isPlain = this.plain;
|
|
|
|
|
2023-04-13 09:33:53 +09:00
|
|
|
const ast = (isPlain ? mfm.parseSimple : mfm.parse)(this.text);
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2021-01-03 12:51:50 +09:00
|
|
|
const validTime = (t: string | null | undefined) => {
|
|
|
|
if (t == null) return null;
|
|
|
|
return t.match(/^[0-9.]+s$/) ? t : null;
|
|
|
|
};
|
2023-06-06 04:28:42 +09:00
|
|
|
// const validEase = (e: string | null | undefined) => {
|
|
|
|
// if (e == null) return null;
|
2023-06-06 08:40:48 +09:00
|
|
|
// return e.match(/(steps)?\(-?[0-9.]+,-?[0-9.]+,-?[0-9.]+,-?[0-9.]+\)/)
|
2023-06-06 04:28:42 +09:00
|
|
|
// ? (e.startsWith("steps") ? e : "cubic-bezier" + e)
|
|
|
|
// : null
|
|
|
|
// }
|
2021-01-03 12:51:50 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
const genEl = (ast: mfm.MfmNode[]) =>
|
|
|
|
concat(
|
2023-04-10 14:42:17 +09:00
|
|
|
ast.map((token, index): VNode[] => {
|
2023-01-13 13:40:33 +09:00
|
|
|
switch (token.type) {
|
|
|
|
case "text": {
|
|
|
|
const text = token.props.text.replace(/(\r\n|\n|\r)/g, "\n");
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
if (!this.plain) {
|
|
|
|
const res = [];
|
|
|
|
for (const t of text.split("\n")) {
|
|
|
|
res.push(h("br"));
|
|
|
|
res.push(t);
|
|
|
|
}
|
|
|
|
res.shift();
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
return [text.replace(/\n/g, " ")];
|
|
|
|
}
|
2021-04-15 12:37:58 +09:00
|
|
|
}
|
2018-08-03 23:27:37 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "bold": {
|
|
|
|
return [h("b", genEl(token.children))];
|
2020-11-07 23:41:21 +09:00
|
|
|
}
|
2023-01-13 13:40:33 +09:00
|
|
|
|
|
|
|
case "strike": {
|
|
|
|
return [h("del", genEl(token.children))];
|
2020-11-08 17:08:51 +09:00
|
|
|
}
|
2023-01-13 13:40:33 +09:00
|
|
|
|
|
|
|
case "italic": {
|
|
|
|
return h(
|
|
|
|
"i",
|
|
|
|
{
|
|
|
|
style: "font-style: oblique;",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
);
|
2022-11-30 11:40:12 +09:00
|
|
|
}
|
2023-01-13 13:40:33 +09:00
|
|
|
|
|
|
|
case "fn": {
|
|
|
|
// TODO: CSSを文字列で組み立てていくと token.props.args.~~~ 経由でCSSインジェクションできるのでよしなにやる
|
|
|
|
let style;
|
|
|
|
switch (token.props.name) {
|
|
|
|
case "tada": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "1s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
2023-06-06 04:28:42 +09:00
|
|
|
// const ease = validEase(token.props.args.ease) || "linear";
|
|
|
|
style = `font-size: 150%; animation: tada ${speed} ${delay} linear infinite both;`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "jelly": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "1s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-rubberBand ${speed} ${delay} linear infinite both;`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "twitch": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "0.5s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-twitch ${speed} ${delay} ease infinite;`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "shake": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "0.5s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-shake ${speed} ${delay} ease infinite;`;
|
2023-01-13 13:40:33 +09: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-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: ${anime} ${speed} ${delay} linear infinite; animation-direction: ${direction};`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "jump": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "0.75s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-jump ${speed} ${delay} linear infinite;`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "bounce": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "0.75s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-bounce ${speed} ${delay} linear infinite; transform-origin: center bottom;`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "rainbow": {
|
|
|
|
const speed = validTime(token.props.args.speed) || "1s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-rainbow ${speed} ${delay} linear infinite;`;
|
2023-01-13 13:40:33 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "sparkle": {
|
2023-05-13 10:48:58 +09:00
|
|
|
if (reducedMotion()) {
|
2023-01-13 13:40:33 +09:00
|
|
|
return genEl(token.children);
|
|
|
|
}
|
|
|
|
return h(MkSparkle, {}, genEl(token.children));
|
|
|
|
}
|
2023-05-23 09:26:27 +09:00
|
|
|
case "fade": {
|
|
|
|
const direction = token.props.args.out
|
|
|
|
? "alternate-reverse"
|
|
|
|
: "alternate";
|
|
|
|
const speed = validTime(token.props.args.speed) || "1.5s";
|
2023-06-03 03:44:41 +09:00
|
|
|
const delay = validTime(token.props.args.delay) || "0s";
|
|
|
|
style = `animation: mfm-fade ${speed} ${delay} linear infinite; animation-direction: ${direction};`;
|
2023-05-23 09:26:27 +09:00
|
|
|
break;
|
|
|
|
}
|
2023-01-13 13:40:33 +09:00
|
|
|
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: "mfm-x2",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "x3": {
|
|
|
|
return h(
|
|
|
|
"span",
|
|
|
|
{
|
|
|
|
class: "mfm-x3",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "x4": {
|
|
|
|
return h(
|
|
|
|
"span",
|
|
|
|
{
|
|
|
|
class: "mfm-x4",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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",
|
|
|
|
{
|
2023-04-07 14:28:44 +09:00
|
|
|
class: "_blur_text",
|
2023-01-13 13:40:33 +09:00
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "rotate": {
|
|
|
|
const rotate = token.props.args.x
|
|
|
|
? "perspective(128px) rotateX"
|
|
|
|
: token.props.args.y
|
|
|
|
? "perspective(128px) rotateY"
|
|
|
|
: "rotate";
|
|
|
|
const degrees = parseInt(token.props.args.deg) || "90";
|
|
|
|
style = `transform: ${rotate}(${degrees}deg); transform-origin: center center;`;
|
|
|
|
break;
|
|
|
|
}
|
2023-02-13 13:25:23 +09:00
|
|
|
case "position": {
|
|
|
|
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;
|
|
|
|
}
|
2023-05-28 14:19:57 +09:00
|
|
|
case "crop": {
|
2023-05-29 02:31:06 +09:00
|
|
|
const top = parseFloat(token.props.args.top ?? "0");
|
|
|
|
const right = parseFloat(token.props.args.right ?? "0");
|
|
|
|
const bottom = parseFloat(token.props.args.bottom ?? "0");
|
|
|
|
const left = parseFloat(token.props.args.left ?? "0");
|
|
|
|
style = `clip-path: inset(${top}% ${right}% ${bottom}% ${left}%);`;
|
2023-05-28 14:19:57 +09:00
|
|
|
break;
|
|
|
|
}
|
2023-02-13 13:25:23 +09:00
|
|
|
case "scale": {
|
|
|
|
const x = Math.min(parseFloat(token.props.args.x ?? "1"), 5);
|
|
|
|
const y = Math.min(parseFloat(token.props.args.y ?? "1"), 5);
|
|
|
|
style = `transform: scale(${x}, ${y});`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "fg": {
|
|
|
|
let color = token.props.args.color;
|
|
|
|
if (!/^[0-9a-f]{3,6}$/i.test(color)) color = "f00";
|
|
|
|
style = `color: #${color};`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "bg": {
|
|
|
|
let color = token.props.args.color;
|
|
|
|
if (!/^[0-9a-f]{3,6}$/i.test(color)) color = "f00";
|
|
|
|
style = `background-color: #${color};`;
|
|
|
|
break;
|
|
|
|
}
|
2023-01-13 13:40:33 +09:00
|
|
|
}
|
|
|
|
if (style == null) {
|
|
|
|
return h("span", {}, [
|
|
|
|
"$[",
|
|
|
|
token.props.name,
|
|
|
|
" ",
|
|
|
|
...genEl(token.children),
|
|
|
|
"]",
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return h(
|
|
|
|
"span",
|
|
|
|
{
|
|
|
|
style: `display: inline-block;${style}`,
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
);
|
2022-11-30 11:40:12 +09:00
|
|
|
}
|
2021-11-26 13:39:57 +09:00
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "small": {
|
|
|
|
return [
|
|
|
|
h(
|
|
|
|
"small",
|
|
|
|
{
|
|
|
|
style: "opacity: 0.7;",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2018-12-05 20:11:54 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "center": {
|
|
|
|
return [
|
|
|
|
h(
|
|
|
|
"div",
|
|
|
|
{
|
|
|
|
style: "text-align:center;",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2018-11-25 13:36:40 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "url": {
|
|
|
|
return [
|
|
|
|
h(MkUrl, {
|
|
|
|
key: Math.random(),
|
|
|
|
url: token.props.url,
|
|
|
|
rel: "nofollow noopener",
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "link": {
|
|
|
|
return [
|
|
|
|
h(
|
|
|
|
MkLink,
|
|
|
|
{
|
|
|
|
key: Math.random(),
|
|
|
|
url: token.props.url,
|
|
|
|
rel: "nofollow noopener",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "mention": {
|
|
|
|
return [
|
|
|
|
h(MkMention, {
|
|
|
|
key: Math.random(),
|
|
|
|
host:
|
|
|
|
(token.props.host == null &&
|
|
|
|
this.author &&
|
|
|
|
this.author.host != null
|
|
|
|
? this.author.host
|
|
|
|
: token.props.host) || host,
|
|
|
|
username: token.props.username,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "hashtag": {
|
|
|
|
return [
|
|
|
|
h(
|
|
|
|
MkA,
|
|
|
|
{
|
|
|
|
key: Math.random(),
|
2023-04-20 13:00:01 +09:00
|
|
|
to: `/tags/${encodeURIComponent(token.props.hashtag)}`,
|
2023-01-13 13:40:33 +09:00
|
|
|
style: "color:var(--hashtag);",
|
|
|
|
},
|
|
|
|
`#${token.props.hashtag}`,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "blockCode": {
|
|
|
|
return [
|
|
|
|
h(MkCode, {
|
|
|
|
key: Math.random(),
|
|
|
|
code: token.props.code,
|
|
|
|
lang: token.props.lang,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "inlineCode": {
|
|
|
|
return [
|
|
|
|
h(MkCode, {
|
|
|
|
key: Math.random(),
|
|
|
|
code: token.props.code,
|
|
|
|
inline: true,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "quote": {
|
|
|
|
if (!this.nowrap) {
|
2023-02-11 08:41:19 +09:00
|
|
|
return [h("blockquote", genEl(token.children))];
|
2023-01-13 13:40:33 +09:00
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
h(
|
|
|
|
"span",
|
|
|
|
{
|
|
|
|
class: "quote",
|
|
|
|
},
|
|
|
|
genEl(token.children),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "emojiCode": {
|
|
|
|
return [
|
|
|
|
h(MkEmoji, {
|
|
|
|
key: Math.random(),
|
|
|
|
emoji: `:${token.props.name}:`,
|
|
|
|
customEmojis: this.customEmojis,
|
|
|
|
normal: this.plain,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2021-04-02 10:36:11 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "unicodeEmoji": {
|
|
|
|
return [
|
|
|
|
h(MkEmoji, {
|
|
|
|
key: Math.random(),
|
|
|
|
emoji: token.props.emoji,
|
|
|
|
customEmojis: this.customEmojis,
|
|
|
|
normal: this.plain,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "mathInline": {
|
|
|
|
return [
|
|
|
|
h(MkFormula, {
|
|
|
|
key: Math.random(),
|
|
|
|
formula: token.props.formula,
|
|
|
|
block: false,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2019-01-25 23:08:06 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "mathBlock": {
|
|
|
|
return [
|
|
|
|
h(MkFormula, {
|
|
|
|
key: Math.random(),
|
|
|
|
formula: token.props.formula,
|
|
|
|
block: true,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-11-16 17:03:52 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "search": {
|
2023-04-10 14:42:17 +09:00
|
|
|
// Disable "search" keyword
|
|
|
|
// (see the issue #9816 on Codeberg)
|
2023-04-16 02:53:17 +09:00
|
|
|
if (token.props.content.slice(-6).toLowerCase() === "search") {
|
2023-04-10 14:42:17 +09:00
|
|
|
const sentinel = "#";
|
|
|
|
let ast2 = (isPlain ? mfm.parseSimple : mfm.parse)(
|
|
|
|
token.props.content.slice(0, -6) + sentinel,
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
ast2[ast2.length - 1].type === "text" &&
|
|
|
|
ast2[ast2.length - 1].props.text.endsWith(sentinel)
|
|
|
|
) {
|
|
|
|
ast2[ast2.length - 1].props.text = ast2[
|
|
|
|
ast2.length - 1
|
|
|
|
].props.text.slice(0, -1);
|
2023-04-16 02:53:17 +09:00
|
|
|
} else {
|
|
|
|
// I don't think this scope is reachable
|
|
|
|
console.warn(
|
|
|
|
"Something went wrong while parsing MFM. Please send a bug report, if possible.",
|
|
|
|
);
|
2023-04-10 14:42:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
let prefix = "\n";
|
|
|
|
if (
|
|
|
|
index === 0 ||
|
2023-04-16 02:53:17 +09:00
|
|
|
[
|
|
|
|
"blockCode",
|
|
|
|
"center",
|
|
|
|
"mathBlock",
|
|
|
|
"quote",
|
|
|
|
"search",
|
|
|
|
].includes(ast[index - 1].type)
|
2023-04-10 14:42:17 +09:00
|
|
|
) {
|
|
|
|
prefix = "";
|
|
|
|
}
|
|
|
|
|
2023-04-16 02:53:17 +09:00
|
|
|
return [
|
|
|
|
prefix,
|
|
|
|
...genEl(ast2),
|
|
|
|
`${token.props.content.slice(-6)}\n`,
|
|
|
|
];
|
2023-04-10 14:42:17 +09:00
|
|
|
}
|
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
return [
|
|
|
|
h(MkGoogle, {
|
|
|
|
key: Math.random(),
|
|
|
|
q: token.props.query,
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
2018-04-21 18:59:16 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
case "plain": {
|
|
|
|
return [h("span", genEl(token.children))];
|
|
|
|
}
|
2022-07-12 12:03:38 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
default: {
|
|
|
|
console.error("unrecognized ast type:", token.type);
|
2018-09-12 03:32:47 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
2018-03-31 21:41:08 +09:00
|
|
|
|
2018-11-21 05:11:00 +09:00
|
|
|
// Parse ast to DOM
|
2023-01-13 13:40:33 +09:00
|
|
|
return h("span", genEl(ast));
|
2022-06-23 21:46:15 +09:00
|
|
|
},
|
2018-03-31 21:41:08 +09:00
|
|
|
});
|