Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7d5f597f3 | ||
![]() |
79c7712241 | ||
![]() |
8f5f3985f4 |
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "10.56.1",
|
"version": "10.56.2",
|
||||||
"clientVersion": "2.0.11960",
|
"clientVersion": "2.0.11963",
|
||||||
"codename": "nighthike",
|
"codename": "nighthike",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
@@ -63,6 +63,7 @@ const mfm = P.createLanguage({
|
|||||||
P.regexp(/^\*\*\*([\s\S]+?)\*\*\*/, 1)
|
P.regexp(/^\*\*\*([\s\S]+?)\*\*\*/, 1)
|
||||||
.map(x => makeNodeWithChildren('big', P.alt(
|
.map(x => makeNodeWithChildren('big', P.alt(
|
||||||
r.mention,
|
r.mention,
|
||||||
|
r.hashtag,
|
||||||
r.emoji,
|
r.emoji,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1).tryParse(x))),
|
).atLeast(1).tryParse(x))),
|
||||||
@@ -85,6 +86,7 @@ const mfm = P.createLanguage({
|
|||||||
P.regexp(/\*\*([\s\S]+?)\*\*/, 1)
|
P.regexp(/\*\*([\s\S]+?)\*\*/, 1)
|
||||||
.map(x => makeNodeWithChildren('bold', P.alt(
|
.map(x => makeNodeWithChildren('bold', P.alt(
|
||||||
r.mention,
|
r.mention,
|
||||||
|
r.hashtag,
|
||||||
r.emoji,
|
r.emoji,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1).tryParse(x))),
|
).atLeast(1).tryParse(x))),
|
||||||
@@ -110,7 +112,7 @@ const mfm = P.createLanguage({
|
|||||||
const text = input.substr(i);
|
const text = input.substr(i);
|
||||||
const match = text.match(/^#([^\s\.,!\?#]+)/i);
|
const match = text.match(/^#([^\s\.,!\?#]+)/i);
|
||||||
if (!match) return P.makeFailure(i, 'not a hashtag');
|
if (!match) return P.makeFailure(i, 'not a hashtag');
|
||||||
if (input[i - 1] != ' ' && input[i - 1] != null) return P.makeFailure(i, 'require space before "#"');
|
if (input[i - 1] != '\n' && input[i - 1] != ' ' && input[i - 1] != null) return P.makeFailure(i, 'require space before "#"');
|
||||||
return P.makeSuccess(i + match[0].length, makeNode('hashtag', { hashtag: match[1] }));
|
return P.makeSuccess(i + match[0].length, makeNode('hashtag', { hashtag: match[1] }));
|
||||||
}),
|
}),
|
||||||
//#endregion
|
//#endregion
|
||||||
@@ -176,6 +178,7 @@ const mfm = P.createLanguage({
|
|||||||
.map(x => makeNodeWithChildren('motion', P.alt(
|
.map(x => makeNodeWithChildren('motion', P.alt(
|
||||||
r.bold,
|
r.bold,
|
||||||
r.mention,
|
r.mention,
|
||||||
|
r.hashtag,
|
||||||
r.emoji,
|
r.emoji,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1).tryParse(x))),
|
).atLeast(1).tryParse(x))),
|
||||||
|
59
test/mfm.ts
59
test/mfm.ts
@@ -162,27 +162,48 @@ describe('Text', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hashtag', () => {
|
describe('hashtag', () => {
|
||||||
const tokens1 = analyze('Strawberry Pasta #alice');
|
it('simple', () => {
|
||||||
assert.deepEqual([
|
const tokens = analyze('#alice');
|
||||||
text('Strawberry Pasta '),
|
assert.deepEqual([
|
||||||
node('hashtag', { hashtag: 'alice' })
|
node('hashtag', { hashtag: 'alice' })
|
||||||
], tokens1);
|
], tokens);
|
||||||
|
});
|
||||||
|
|
||||||
const tokens2 = analyze('Foo #bar, baz #piyo.');
|
it('after line break', () => {
|
||||||
assert.deepEqual([
|
const tokens = analyze('foo\n#alice');
|
||||||
text('Foo '),
|
assert.deepEqual([
|
||||||
node('hashtag', { hashtag: 'bar' }),
|
text('foo\n'),
|
||||||
text(', baz '),
|
node('hashtag', { hashtag: 'alice' })
|
||||||
node('hashtag', { hashtag: 'piyo' }),
|
], tokens);
|
||||||
text('.'),
|
});
|
||||||
], tokens2);
|
|
||||||
|
|
||||||
const tokens3 = analyze('#Foo!');
|
it('with text', () => {
|
||||||
assert.deepEqual([
|
const tokens = analyze('Strawberry Pasta #alice');
|
||||||
node('hashtag', { hashtag: 'Foo' }),
|
assert.deepEqual([
|
||||||
text('!'),
|
text('Strawberry Pasta '),
|
||||||
], tokens3);
|
node('hashtag', { hashtag: 'alice' })
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignore comma and period', () => {
|
||||||
|
const tokens = analyze('Foo #bar, baz #piyo.');
|
||||||
|
assert.deepEqual([
|
||||||
|
text('Foo '),
|
||||||
|
node('hashtag', { hashtag: 'bar' }),
|
||||||
|
text(', baz '),
|
||||||
|
node('hashtag', { hashtag: 'piyo' }),
|
||||||
|
text('.'),
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignore exclamation mark', () => {
|
||||||
|
const tokens = analyze('#Foo!');
|
||||||
|
assert.deepEqual([
|
||||||
|
node('hashtag', { hashtag: 'Foo' }),
|
||||||
|
text('!'),
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('quote', () => {
|
describe('quote', () => {
|
||||||
|
Reference in New Issue
Block a user