Skip to content

Commit

Permalink
Add rotate DEG
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed May 12, 2019
1 parent 428be0b commit 85719e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
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 @@ -177,6 +177,17 @@ export default Vue.component('misskey-flavored-markdown', {
}, genEl(token.children));
}

case 'rotate': {
const isLong = sumTextsLength(token.children) > 100 || countNodesF(token.children) > 20;
const deg = token.node.props.attr;

return (createElement as any)('span', {
attrs: {
style: isLong ? '' : `display: inline-block; transform: rotate(${deg}deg);`
},
}, genEl(token.children));
}

case 'url': {
return [createElement(MkUrl, {
key: Math.random(),
Expand Down
15 changes: 15 additions & 0 deletions src/mfm/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const mfmLanguage = P.createLanguage({
r.jump,
r.flip,
r.vflip,
r.rotate,
r.inlineCode,
r.mathInline,
r.mention,
Expand Down Expand Up @@ -133,6 +134,20 @@ export const mfmLanguage = P.createLanguage({
jump: r => P.alt(P.regexp(/<jump>(.+?)<\/jump>/, 1), P.regexp(/\{\{\{([\s\S]+?)\}\}\}/, 1)).map(x => createTree('jump', r.inline.atLeast(1).tryParse(x), {})),
flip: r => P.regexp(/<flip>(.+?)<\/flip>/, 1).map(x => createTree('flip', r.inline.atLeast(1).tryParse(x), {})),
vflip: r => P.regexp(/<vflip>(.+?)<\/vflip>/, 1).map(x => createTree('vflip', r.inline.atLeast(1).tryParse(x), {})),
rotate: r => {
return P((input, i) => {
const text = input.substr(i);
const match = text.match(/^<rotate\s+([+-]?\d+)>(.+?)<\/rotate>/i);

if (match) {
return P.makeSuccess(i + match[0].length, {
content: match[2], attr: match[1]
});
} else {
return P.makeFailure(i, 'not a rotate');
}
}).map(x => createTree('rotate', r.inline.atLeast(1).tryParse(x.content), { attr: x.attr }));
},
center: r => r.startOfLine.then(P.regexp(/<center>([\s\S]+?)<\/center>/, 1).map(x => createTree('center', r.inline.atLeast(1).tryParse(x), {}))),
inlineCode: () => P.regexp(/`([^´\n]+?)`/, 1).map(x => createLeaf('inlineCode', { code: x })),
mathBlock: r => r.startOfLine.then(P.regexp(/\\\[([\s\S]+?)\\\]/, 1).map(x => createLeaf('mathBlock', { formula: x.trim() }))),
Expand Down
6 changes: 6 additions & 0 deletions src/mfm/toHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export function toHtml(tokens: MfmForest, mentionedRemoteUsers: INote['mentioned
return el;
},

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

blockCode(token) {
const pre = doc.createElement('pre');
const inner = doc.createElement('code');
Expand Down
11 changes: 11 additions & 0 deletions test/mfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ describe('MFM', () => {
]);
});

it('rotate', () => {
const tokens = parse('<rotate 90>foo</rotate>');
assert.deepStrictEqual(tokens, [
tree('rotate', [
text('foo')
], {
attr: '90'
}),
]);
});

describe('spin', () => {
it('text', () => {
const tokens = parse('<spin>foo</spin>');
Expand Down

0 comments on commit 85719e7

Please sign in to comment.