[MFM] Implement strike syntax

Resolve #3485
This commit is contained in:
syuilo 2018-12-04 01:28:21 +09:00
parent ce3f735654
commit 6e343d50f1
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
4 changed files with 40 additions and 0 deletions

View file

@ -96,6 +96,10 @@ export default Vue.component('misskey-flavored-markdown', {
return [createElement('b', genEl(token.children))]; return [createElement('b', genEl(token.children))];
} }
case 'strike': {
return [createElement('del', genEl(token.children))];
}
case 'big': { case 'big': {
bigCount++; bigCount++;
const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5; const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5;

View file

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

View file

@ -68,6 +68,7 @@ const mfm = P.createLanguage({
root: r => P.alt( root: r => P.alt(
r.big, r.big,
r.bold, r.bold,
r.strike,
r.motion, r.motion,
r.url, r.url,
r.link, r.link,
@ -129,6 +130,7 @@ const mfm = P.createLanguage({
.map(x => makeNodeWithChildren('center', P.alt( .map(x => makeNodeWithChildren('center', P.alt(
r.big, r.big,
r.bold, r.bold,
r.strike,
r.motion, r.motion,
r.mention, r.mention,
r.hashtag, r.hashtag,
@ -189,6 +191,7 @@ const mfm = P.createLanguage({
return makeNodeWithChildren('link', P.alt( return makeNodeWithChildren('link', P.alt(
r.big, r.big,
r.bold, r.bold,
r.strike,
r.motion, r.motion,
r.emoji, r.emoji,
r.text r.text
@ -228,6 +231,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.strike,
r.mention, r.mention,
r.hashtag, r.hashtag,
r.emoji, r.emoji,
@ -261,6 +265,20 @@ const mfm = P.createLanguage({
})), })),
//#endregion //#endregion
//#region Strike
strike: r =>
P.regexp(/~~(.+?)~~/, 1)
.map(x => makeNodeWithChildren('strike', P.alt(
r.bold,
r.mention,
r.hashtag,
r.url,
r.link,
r.emoji,
r.text
).atLeast(1).tryParse(x))),
//#endregion
//#region Title //#region Title
title: r => title: r =>
newline.then(P((input, i) => { newline.then(P((input, i) => {
@ -271,6 +289,7 @@ const mfm = P.createLanguage({
const contents = P.alt( const contents = P.alt(
r.big, r.big,
r.bold, r.bold,
r.strike,
r.motion, r.motion,
r.url, r.url,
r.link, r.link,

View file

@ -702,6 +702,17 @@ describe('Text', () => {
], tokens); ], tokens);
}); });
}); });
describe('strike', () => {
it('simple', () => {
const tokens = analyze('~~foo~~');
assert.deepEqual([
nodeWithChildren('strike', [
text('foo')
]),
], tokens);
});
});
}); });
describe('toHtml', () => { describe('toHtml', () => {