Skip to content

Commit

Permalink
[MFM] Add spin syntax
Browse files Browse the repository at this point in the history
Resolve #4003
  • Loading branch information
syuilo committed Jan 27, 2019
1 parent d906d90 commit e5d9381
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unreleased
* 外部サービス認証情報の配信
* 管理画面のモデレーションのUIを強化
* 管理画面からリモートユーザーの情報を更新できるように
* 回転構文の追加
* シンタックスハイライトの強化
* 引用投稿を削除したとき単なるRenoteとしてタイムラインに残る問題を修正
* イタリック構文の判定の改善
Expand Down
5 changes: 5 additions & 0 deletions src/client/app/animation.styl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
transform: translateY(0);
}
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
11 changes: 11 additions & 0 deletions src/client/app/common/views/components/mfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ export default Vue.component('misskey-flavored-markdown', {
}, genEl(token.children));
}

case 'spin': {
motionCount++;
const isLong = sumTextsLength(token.children) > 5 || countNodesF(token.children) > 3;
const isMany = motionCount > 3;
return (createElement as any)('span', {
attrs: {
style: (this.$store.state.settings.disableAnimatedMfm || isLong || isMany) ? 'display: inline-block;' : 'display: inline-block; animation: spin 1.5s linear infinite;'
},
}, genEl(token.children));
}

case 'url': {
return [createElement(MkUrl, {
key: Math.random(),
Expand Down
6 changes: 6 additions & 0 deletions src/mfm/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default (tokens: MfmForest, mentionedRemoteUsers: INote['mentionedRemoteU
return el;
},

spin(token) {
const el = doc.createElement('i');
appendChildren(token.children, el);
return el;
},

blockCode(token) {
const pre = doc.createElement('pre');
const inner = doc.createElement('code');
Expand Down
15 changes: 15 additions & 0 deletions src/mfm/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const mfm = P.createLanguage({
root: r => P.alt(
r.big,
r.small,
r.spin,
r.bold,
r.strike,
r.italic,
Expand Down Expand Up @@ -122,6 +123,7 @@ const mfm = P.createLanguage({
r.hashtag,
r.emoji,
r.math,
r.spin,
r.text
).atLeast(1).tryParse(x), {})),
//#endregion
Expand All @@ -140,6 +142,15 @@ const mfm = P.createLanguage({
).atLeast(1).tryParse(x), {})),
//#endregion

//#region Spin
spin: r =>
P.regexp(/<spin>(.+?)<\/spin>/, 1)
.map(x => createTree('spin', P.alt(
r.emoji,
r.text
).atLeast(1).tryParse(x), {})),
//#endregion

//#region Block code
blockCode: r =>
newline.then(
Expand Down Expand Up @@ -173,6 +184,7 @@ const mfm = P.createLanguage({
.map(x => createTree('center', P.alt(
r.big,
r.small,
r.spin,
r.bold,
r.strike,
r.italic,
Expand Down Expand Up @@ -261,6 +273,7 @@ const mfm = P.createLanguage({
return createTree('link', P.alt(
r.big,
r.small,
r.spin,
r.bold,
r.strike,
r.italic,
Expand Down Expand Up @@ -304,6 +317,7 @@ const mfm = P.createLanguage({
.map(x => createTree('motion', P.alt(
r.bold,
r.small,
r.spin,
r.strike,
r.italic,
r.mention,
Expand Down Expand Up @@ -364,6 +378,7 @@ const mfm = P.createLanguage({
const contents = P.alt(
r.big,
r.small,
r.spin,
r.bold,
r.strike,
r.italic,
Expand Down
9 changes: 9 additions & 0 deletions test/mfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ describe('MFM', () => {
]);
});

it('spin', () => {
const tokens = analyze('<spin>:foo:</spin>');
assert.deepStrictEqual(tokens, [
tree('spin', [
leaf('emoji', { name: 'foo' })
], {}),
]);
});

describe('motion', () => {
it('by triple brackets', () => {
const tokens = analyze('(((foo)))');
Expand Down

0 comments on commit e5d9381

Please sign in to comment.