From 5bbc95d6597625772ae305e6a81fb7b1ddace5b7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Aug 2018 19:20:26 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E5=AD=97=E6=95=B0=E3=81=8C=E5=A4=9A?= =?UTF-8?q?=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AF=E5=8B=95=E3=81=8D=E3=82=92?= =?UTF-8?q?=E7=84=A1=E5=8A=B9=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + .../components/misskey-flavored-markdown.ts | 52 +++++++++++++------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index dea93d11a..2da5bf0ec 100644 --- a/package.json +++ b/package.json @@ -183,6 +183,7 @@ "showdown-highlightjs-extension": "0.1.2", "single-line-log": "1.1.2", "speakeasy": "2.0.0", + "stringz": "1.0.0", "style-loader": "0.21.0", "stylus": "0.54.5", "stylus-loader": "3.0.2", diff --git a/src/client/app/common/views/components/misskey-flavored-markdown.ts b/src/client/app/common/views/components/misskey-flavored-markdown.ts index 683b4e806..69e727d6f 100644 --- a/src/client/app/common/views/components/misskey-flavored-markdown.ts +++ b/src/client/app/common/views/components/misskey-flavored-markdown.ts @@ -1,5 +1,6 @@ import Vue from 'vue'; import * as emojilib from 'emojilib'; +import { length } from 'stringz'; import parse from '../../../../../mfm/parse'; import getAcct from '../../../../../misc/acct/render'; import { url } from '../../../config'; @@ -43,7 +44,7 @@ export default Vue.component('misskey-flavored-markdown', { // Parse ast to DOM const els = flatten(ast.map(token => { switch (token.type) { - case 'text': + case 'text': { const text = token.content.replace(/(\r\n|\n|\r)/g, '\n'); if (this.shouldBreak) { @@ -54,41 +55,48 @@ export default Vue.component('misskey-flavored-markdown', { } else { return createElement('span', text.replace(/\n/g, ' ')); } + } - case 'bold': + case 'bold': { return createElement('b', token.bold); + } - case 'big': + case 'big': { + const isLong = length(token.big) > 10; return (createElement as any)('strong', { attrs: { style: 'display: inline-block; font-size: 200%;' }, - directives: [this.$store.state.settings.disableAnimatedMfm ? {} : { + directives: [this.$store.state.settings.disableAnimatedMfm || isLong ? {} : { name: 'animate-css', value: { classes: 'tada', iteration: 'infinite' } }] }, token.big); + } - case 'motion': + case 'motion': { + const isLong = length(token.motion) > 10; return (createElement as any)('span', { attrs: { style: 'display: inline-block;' }, - directives: [this.$store.state.settings.disableAnimatedMfm ? {} : { + directives: [this.$store.state.settings.disableAnimatedMfm || isLong ? {} : { name: 'animate-css', value: { classes: 'rubberBand', iteration: 'infinite' } }] }, token.motion); + } - case 'url': + case 'url': { return createElement(MkUrl, { props: { url: token.content, target: '_blank' } }); + } - case 'link': + case 'link': { return createElement('a', { attrs: { class: 'link', @@ -97,8 +105,9 @@ export default Vue.component('misskey-flavored-markdown', { title: token.url } }, token.title); + } - case 'mention': + case 'mention': { return (createElement as any)('a', { attrs: { href: `${url}/@${getAcct(token)}`, @@ -110,16 +119,18 @@ export default Vue.component('misskey-flavored-markdown', { value: token.content }] }, token.content); + } - case 'hashtag': + case 'hashtag': { return createElement('a', { attrs: { href: `${url}/tags/${encodeURIComponent(token.hashtag)}`, target: '_blank' } }, token.content); + } - case 'code': + case 'code': { return createElement('pre', { class: 'code' }, [ @@ -129,15 +140,17 @@ export default Vue.component('misskey-flavored-markdown', { } }) ]); + } - case 'inline-code': + case 'inline-code': { return createElement('code', { domProps: { innerHTML: token.html } }); + } - case 'quote': + case 'quote': { const text2 = token.quote.replace(/(\r\n|\n|\r)/g, '\n'); if (this.shouldBreak) { @@ -156,27 +169,32 @@ export default Vue.component('misskey-flavored-markdown', { } }, text2.replace(/\n/g, ' ')); } + } - case 'title': + case 'title': { return createElement('div', { attrs: { class: 'title' } }, token.title); + } - case 'emoji': + case 'emoji': { const emoji = emojilib.lib[token.emoji]; return createElement('span', emoji ? emoji.char : token.content); + } - case 'search': + case 'search': { return createElement(MkGoogle, { props: { q: token.query } }); + } - default: + default: { console.log('unknown ast type:', token.type); + } } }));