Compare commits

..

3 Commits

Author SHA1 Message Date
syuilo
f7d5f597f3 10.56.2 2018-11-21 08:33:02 +09:00
syuilo
79c7712241 Improve MFM 2018-11-21 08:32:40 +09:00
syuilo
8f5f3985f4 [MFM] Fix hashtag parsing 2018-11-21 08:30:29 +09:00
3 changed files with 46 additions and 22 deletions

View File

@@ -1,8 +1,8 @@
{
"name": "misskey",
"author": "syuilo <i@syuilo.com>",
"version": "10.56.1",
"clientVersion": "2.0.11960",
"version": "10.56.2",
"clientVersion": "2.0.11963",
"codename": "nighthike",
"main": "./built/index.js",
"private": true,

View File

@@ -63,6 +63,7 @@ const mfm = P.createLanguage({
P.regexp(/^\*\*\*([\s\S]+?)\*\*\*/, 1)
.map(x => makeNodeWithChildren('big', P.alt(
r.mention,
r.hashtag,
r.emoji,
r.text
).atLeast(1).tryParse(x))),
@@ -85,6 +86,7 @@ const mfm = P.createLanguage({
P.regexp(/\*\*([\s\S]+?)\*\*/, 1)
.map(x => makeNodeWithChildren('bold', P.alt(
r.mention,
r.hashtag,
r.emoji,
r.text
).atLeast(1).tryParse(x))),
@@ -110,7 +112,7 @@ const mfm = P.createLanguage({
const text = input.substr(i);
const match = text.match(/^#([^\s\.,!\?#]+)/i);
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] }));
}),
//#endregion
@@ -176,6 +178,7 @@ const mfm = P.createLanguage({
.map(x => makeNodeWithChildren('motion', P.alt(
r.bold,
r.mention,
r.hashtag,
r.emoji,
r.text
).atLeast(1).tryParse(x))),

View File

@@ -162,27 +162,48 @@ describe('Text', () => {
});
});
it('hashtag', () => {
const tokens1 = analyze('Strawberry Pasta #alice');
assert.deepEqual([
text('Strawberry Pasta '),
node('hashtag', { hashtag: 'alice' })
], tokens1);
describe('hashtag', () => {
it('simple', () => {
const tokens = analyze('#alice');
assert.deepEqual([
node('hashtag', { hashtag: 'alice' })
], tokens);
});
const tokens2 = analyze('Foo #bar, baz #piyo.');
assert.deepEqual([
text('Foo '),
node('hashtag', { hashtag: 'bar' }),
text(', baz '),
node('hashtag', { hashtag: 'piyo' }),
text('.'),
], tokens2);
it('after line break', () => {
const tokens = analyze('foo\n#alice');
assert.deepEqual([
text('foo\n'),
node('hashtag', { hashtag: 'alice' })
], tokens);
});
const tokens3 = analyze('#Foo!');
assert.deepEqual([
node('hashtag', { hashtag: 'Foo' }),
text('!'),
], tokens3);
it('with text', () => {
const tokens = analyze('Strawberry Pasta #alice');
assert.deepEqual([
text('Strawberry Pasta '),
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', () => {