Refactoring

This commit is contained in:
syuilo 2018-11-22 01:51:26 +09:00
parent ac14adfd3e
commit 67df681a48
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69

View file

@ -9,18 +9,18 @@ import MkGoogle from './google.vue';
import { toUnicode } from 'punycode'; import { toUnicode } from 'punycode';
import syntaxHighlight from '../../../../../mfm/syntax-highlight'; import syntaxHighlight from '../../../../../mfm/syntax-highlight';
function getText(tokens: Node[]): string { function getTextCount(tokens: Node[]): number {
let text = ''; let count = 0;
const extract = (tokens: Node[]) => { const extract = (tokens: Node[]) => {
tokens.filter(x => x.name === 'text').forEach(x => { tokens.filter(x => x.name === 'text').forEach(x => {
text += x.props.text; count += length(x.props.text);
}); });
tokens.filter(x => x.children).forEach(x => { tokens.filter(x => x.children).forEach(x => {
extract(x.children); extract(x.children);
}); });
}; };
extract(tokens); extract(tokens);
return text; return count;
} }
function getChildrenCount(tokens: Node[]): number { function getChildrenCount(tokens: Node[]): number {
@ -98,7 +98,7 @@ export default Vue.component('misskey-flavored-markdown', {
case 'big': { case 'big': {
bigCount++; bigCount++;
const isLong = length(getText(token.children)) > 10 || getChildrenCount(token.children) > 5; const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5;
const isMany = bigCount > 3; const isMany = bigCount > 3;
return (createElement as any)('strong', { return (createElement as any)('strong', {
attrs: { attrs: {
@ -113,7 +113,7 @@ export default Vue.component('misskey-flavored-markdown', {
case 'motion': { case 'motion': {
motionCount++; motionCount++;
const isLong = length(getText(token.children)) > 10 || getChildrenCount(token.children) > 5; const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5;
const isMany = motionCount > 3; const isMany = motionCount > 3;
return (createElement as any)('span', { return (createElement as any)('span', {
attrs: { attrs: {