summaryrefslogtreecommitdiff
path: root/packages/frontend/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-10-19 11:42:17 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-10-19 11:42:17 +0900
commit30efd932a5828def2cd394e65d333fdbdb447231 (patch)
tree5b3ebfbfbad0ccb0bbec5164f19b46eeb59d5933 /packages/frontend/src
parentrefactor and perf tweak (diff)
downloadsharkey-30efd932a5828def2cd394e65d333fdbdb447231.tar.gz
sharkey-30efd932a5828def2cd394e65d333fdbdb447231.tar.bz2
sharkey-30efd932a5828def2cd394e65d333fdbdb447231.zip
enhance: nyaizeはクライアントで表示時に行うように
Resolve #12030
Diffstat (limited to 'packages/frontend/src')
-rw-r--r--packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts16
-rw-r--r--packages/frontend/src/scripts/nyaize.ts20
2 files changed, 30 insertions, 6 deletions
diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts
index 2ae3fc89c8..ea3655f6bb 100644
--- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts
+++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts
@@ -17,6 +17,7 @@ import MkSparkle from '@/components/MkSparkle.vue';
import MkA from '@/components/global/MkA.vue';
import { host } from '@/config.js';
import { defaultStore } from '@/store.js';
+import { nyaize } from '@/scripts/nyaize.js';
const QUOTE_STYLE = `
display: block;
@@ -55,10 +56,13 @@ export default function(props: {
* @param ast MFM AST
* @param scale How times large the text is
*/
- const genEl = (ast: mfm.MfmNode[], scale: number) => ast.map((token): VNode | string | (VNode | string)[] => {
+ const genEl = (ast: mfm.MfmNode[], scale: number, disableNyaize = false) => ast.map((token): VNode | string | (VNode | string)[] => {
switch (token.type) {
case 'text': {
- const text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n');
+ let text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n');
+ if (!disableNyaize && props.author.isCat) {
+ text = nyaize(text);
+ }
if (!props.plain) {
const res: (VNode | string)[] = [];
@@ -260,7 +264,7 @@ export default function(props: {
key: Math.random(),
url: token.props.url,
rel: 'nofollow noopener',
- }, genEl(token.children, scale))];
+ }, genEl(token.children, scale, true))];
}
case 'mention': {
@@ -299,11 +303,11 @@ export default function(props: {
if (!props.nowrap) {
return [h('div', {
style: QUOTE_STYLE,
- }, genEl(token.children, scale))];
+ }, genEl(token.children, scale, true))];
} else {
return [h('span', {
style: QUOTE_STYLE,
- }, genEl(token.children, scale))];
+ }, genEl(token.children, scale, true))];
}
}
@@ -358,7 +362,7 @@ export default function(props: {
}
case 'plain': {
- return [h('span', genEl(token.children, scale))];
+ return [h('span', genEl(token.children, scale, true))];
}
default: {
diff --git a/packages/frontend/src/scripts/nyaize.ts b/packages/frontend/src/scripts/nyaize.ts
new file mode 100644
index 0000000000..0ac77e1006
--- /dev/null
+++ b/packages/frontend/src/scripts/nyaize.ts
@@ -0,0 +1,20 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+export function nyaize(text: string): string {
+ return text
+ // ja-JP
+ .replaceAll('な', 'にゃ').replaceAll('ナ', 'ニャ').replaceAll('ナ', 'ニャ')
+ // en-US
+ .replace(/(?<=n)a/gi, x => x === 'A' ? 'YA' : 'ya')
+ .replace(/(?<=morn)ing/gi, x => x === 'ING' ? 'YAN' : 'yan')
+ .replace(/(?<=every)one/gi, x => x === 'ONE' ? 'NYAN' : 'nyan')
+ // ko-KR
+ .replace(/[나-낳]/g, match => String.fromCharCode(
+ match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0),
+ ))
+ .replace(/(다$)|(다(?=\.))|(다(?= ))|(다(?=!))|(다(?=\?))/gm, '다냥')
+ .replace(/(야(?=\?))|(야$)|(야(?= ))/gm, '냥');
+}