Add small syntax (#3506)

This commit is contained in:
Aya Morisawa 2018-12-05 20:11:54 +09:00 committed by GitHub
parent dc8f4c8d6a
commit 66836836ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View file

@ -123,6 +123,10 @@ export default Vue.component('misskey-flavored-markdown', {
}, genEl(token.children)); }, genEl(token.children));
} }
case 'small': {
return [createElement('small', genEl(token.children))];
}
case 'center': { case 'center': {
return [createElement('div', { return [createElement('div', {
attrs: { attrs: {

View file

@ -31,6 +31,12 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
return el; return el;
}, },
small(token) {
const el = doc.createElement('small');
dive(token.children).forEach(child => el.appendChild(child));
return el;
},
strike(token) { strike(token) {
const el = doc.createElement('del'); const el = doc.createElement('del');
dive(token.children).forEach(child => el.appendChild(child)); dive(token.children).forEach(child => el.appendChild(child));

View file

@ -67,6 +67,7 @@ const newline = P((input, i) => {
const mfm = P.createLanguage({ const mfm = P.createLanguage({
root: r => P.alt( root: r => P.alt(
r.big, r.big,
r.small,
r.bold, r.bold,
r.strike, r.strike,
r.italic, r.italic,
@ -102,6 +103,20 @@ const mfm = P.createLanguage({
).atLeast(1).tryParse(x))), ).atLeast(1).tryParse(x))),
//#endregion //#endregion
//#region Small
small: r =>
P.regexp(/<small>([\s\S]+?)<\/small>/, 1)
.map(x => makeNodeWithChildren('small', P.alt(
r.strike,
r.italic,
r.mention,
r.hashtag,
r.emoji,
r.math,
r.text
).atLeast(1).tryParse(x))),
//#endregion
//#region Block code //#region Block code
blockCode: r => blockCode: r =>
newline.then( newline.then(
@ -134,6 +149,7 @@ const mfm = P.createLanguage({
P.regexp(/<center>([\s\S]+?)<\/center>/, 1) P.regexp(/<center>([\s\S]+?)<\/center>/, 1)
.map(x => makeNodeWithChildren('center', P.alt( .map(x => makeNodeWithChildren('center', P.alt(
r.big, r.big,
r.small,
r.bold, r.bold,
r.strike, r.strike,
r.italic, r.italic,
@ -211,6 +227,7 @@ const mfm = P.createLanguage({
.map((x: any) => { .map((x: any) => {
return makeNodeWithChildren('link', P.alt( return makeNodeWithChildren('link', P.alt(
r.big, r.big,
r.small,
r.bold, r.bold,
r.strike, r.strike,
r.italic, r.italic,
@ -253,6 +270,7 @@ const mfm = P.createLanguage({
P.alt(P.regexp(/\(\(\(([\s\S]+?)\)\)\)/, 1), P.regexp(/<motion>(.+?)<\/motion>/, 1)) P.alt(P.regexp(/\(\(\(([\s\S]+?)\)\)\)/, 1), P.regexp(/<motion>(.+?)<\/motion>/, 1))
.map(x => makeNodeWithChildren('motion', P.alt( .map(x => makeNodeWithChildren('motion', P.alt(
r.bold, r.bold,
r.small,
r.strike, r.strike,
r.italic, r.italic,
r.mention, r.mention,
@ -312,6 +330,7 @@ const mfm = P.createLanguage({
const q = match[1].trim().substring(1, match[1].length - 1); const q = match[1].trim().substring(1, match[1].length - 1);
const contents = P.alt( const contents = P.alt(
r.big, r.big,
r.small,
r.bold, r.bold,
r.strike, r.strike,
r.italic, r.italic,

View file

@ -70,6 +70,15 @@ describe('Text', () => {
], tokens); ], tokens);
}); });
it('small', () => {
const tokens = analyze('<small>smaller</small>');
assert.deepEqual([
nodeWithChildren('small', [
text('smaller')
]),
], tokens);
});
describe('motion', () => { describe('motion', () => {
it('by triple brackets', () => { it('by triple brackets', () => {
const tokens = analyze('(((foo)))'); const tokens = analyze('(((foo)))');