mirror of
https://example.com
synced 2024-11-24 17:06:38 +09:00
[MFM] Implement strike syntax
Resolve #3485
This commit is contained in:
parent
ce3f735654
commit
6e343d50f1
4 changed files with 40 additions and 0 deletions
|
@ -96,6 +96,10 @@ export default Vue.component('misskey-flavored-markdown', {
|
|||
return [createElement('b', genEl(token.children))];
|
||||
}
|
||||
|
||||
case 'strike': {
|
||||
return [createElement('del', genEl(token.children))];
|
||||
}
|
||||
|
||||
case 'big': {
|
||||
bigCount++;
|
||||
const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5;
|
||||
|
|
|
@ -31,6 +31,12 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
|
|||
return el;
|
||||
},
|
||||
|
||||
strike(token) {
|
||||
const el = doc.createElement('del');
|
||||
dive(token.children).forEach(child => el.appendChild(child));
|
||||
return el;
|
||||
},
|
||||
|
||||
motion(token) {
|
||||
const el = doc.createElement('i');
|
||||
dive(token.children).forEach(child => el.appendChild(child));
|
||||
|
|
|
@ -68,6 +68,7 @@ const mfm = P.createLanguage({
|
|||
root: r => P.alt(
|
||||
r.big,
|
||||
r.bold,
|
||||
r.strike,
|
||||
r.motion,
|
||||
r.url,
|
||||
r.link,
|
||||
|
@ -129,6 +130,7 @@ const mfm = P.createLanguage({
|
|||
.map(x => makeNodeWithChildren('center', P.alt(
|
||||
r.big,
|
||||
r.bold,
|
||||
r.strike,
|
||||
r.motion,
|
||||
r.mention,
|
||||
r.hashtag,
|
||||
|
@ -189,6 +191,7 @@ const mfm = P.createLanguage({
|
|||
return makeNodeWithChildren('link', P.alt(
|
||||
r.big,
|
||||
r.bold,
|
||||
r.strike,
|
||||
r.motion,
|
||||
r.emoji,
|
||||
r.text
|
||||
|
@ -228,6 +231,7 @@ const mfm = P.createLanguage({
|
|||
P.alt(P.regexp(/\(\(\(([\s\S]+?)\)\)\)/, 1), P.regexp(/<motion>(.+?)<\/motion>/, 1))
|
||||
.map(x => makeNodeWithChildren('motion', P.alt(
|
||||
r.bold,
|
||||
r.strike,
|
||||
r.mention,
|
||||
r.hashtag,
|
||||
r.emoji,
|
||||
|
@ -261,6 +265,20 @@ const mfm = P.createLanguage({
|
|||
})),
|
||||
//#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
|
||||
title: r =>
|
||||
newline.then(P((input, i) => {
|
||||
|
@ -271,6 +289,7 @@ const mfm = P.createLanguage({
|
|||
const contents = P.alt(
|
||||
r.big,
|
||||
r.bold,
|
||||
r.strike,
|
||||
r.motion,
|
||||
r.url,
|
||||
r.link,
|
||||
|
|
11
test/mfm.ts
11
test/mfm.ts
|
@ -702,6 +702,17 @@ describe('Text', () => {
|
|||
], tokens);
|
||||
});
|
||||
});
|
||||
|
||||
describe('strike', () => {
|
||||
it('simple', () => {
|
||||
const tokens = analyze('~~foo~~');
|
||||
assert.deepEqual([
|
||||
nodeWithChildren('strike', [
|
||||
text('foo')
|
||||
]),
|
||||
], tokens);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toHtml', () => {
|
||||
|
|
Loading…
Reference in a new issue