Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jump syntax #4007

Merged
merged 3 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/client/app/animation.styl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

@keyframes jump {
0% { transform: translateY(0); }
25% { transform: translateY(-16px); }
50% { transform: translateY(0); }
75% { transform: translateY(-8px); }
100% { transform: translateY(0); }
}
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 @@ -135,6 +135,17 @@ export default Vue.component('misskey-flavored-markdown', {
}, genEl(token.children));
}

case 'jump': {
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: jump 0.75s linear infinite;'
},
}, genEl(token.children));
}

case 'flip': {
return (createElement as any)('span', {
attrs: {
Expand Down
6 changes: 6 additions & 0 deletions src/mfm/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export default (tokens: MfmForest, mentionedRemoteUsers: INote['mentionedRemoteU
return el;
},

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

flip(token) {
const el = doc.createElement('span');
appendChildren(token.children, el);
Expand Down
16 changes: 16 additions & 0 deletions src/mfm/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const mfm = P.createLanguage({
r.big,
r.small,
r.spin,
r.jump,
r.bold,
r.strike,
r.italic,
Expand Down Expand Up @@ -126,6 +127,7 @@ const mfm = P.createLanguage({
r.emoji,
r.mathInline,
r.spin,
r.jump,
r.text
).atLeast(1).tryParse(x), {})),
//#endregion
Expand Down Expand Up @@ -153,6 +155,15 @@ const mfm = P.createLanguage({
).atLeast(1).tryParse(x), {})),
//#endregion

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

//#region Block code
blockCode: r =>
newline.then(
Expand Down Expand Up @@ -188,6 +199,7 @@ const mfm = P.createLanguage({
r.big,
r.small,
r.spin,
r.jump,
r.bold,
r.strike,
r.italic,
Expand Down Expand Up @@ -239,6 +251,7 @@ const mfm = P.createLanguage({
r.big,
r.small,
r.spin,
r.jump,
r.bold,
r.strike,
r.link,
Expand Down Expand Up @@ -296,6 +309,7 @@ const mfm = P.createLanguage({
r.big,
r.small,
r.spin,
r.jump,
r.bold,
r.strike,
r.italic,
Expand Down Expand Up @@ -346,6 +360,7 @@ const mfm = P.createLanguage({
r.bold,
r.small,
r.spin,
r.jump,
r.strike,
r.italic,
r.mention,
Expand Down Expand Up @@ -409,6 +424,7 @@ const mfm = P.createLanguage({
r.big,
r.small,
r.spin,
r.jump,
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 @@ -262,6 +262,15 @@ describe('MFM', () => {
]);
});

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

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