Skip to content

Commit 11a763f

Browse files
committed
Merge branch 'develop' into master
2 parents 2163d38 + 229eb1e commit 11a763f

File tree

4 files changed

+54
-89
lines changed

4 files changed

+54
-89
lines changed

Diff for: package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "mfm-js",
3-
"version": "0.16.4",
3+
"version": "0.16.5",
44
"description": "An MFM parser implementation with PEG.js",
55
"main": "./built/index.js",
66
"types": "./built/index.d.ts",
77
"scripts": {
88
"build": "npm run tsc && npm run peg",
99
"build-debug": "npm run tsc && npm run peg-debug",
10-
"peg": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser.pegjs",
11-
"peg-debug": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser.pegjs",
10+
"peg": "peggy --cache -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser.pegjs",
11+
"peg-debug": "peggy --cache -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser.pegjs",
1212
"tsc": "tsc",
1313
"tsd": "tsd",
1414
"parse": "node ./built/cli/parse",
@@ -24,9 +24,8 @@
2424
"devDependencies": {
2525
"@types/mocha": "8.2.x",
2626
"@types/node": "14.14.x",
27-
"@types/pegjs": "0.10.x",
2827
"mocha": "8.3.x",
29-
"pegjs": "0.10.x",
28+
"peggy": "1.2.0",
3029
"ts-node": "9.1.x",
3130
"tsd": "^0.14.0",
3231
"typescript": "4.2.x"

Diff for: src/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import peg from 'pegjs';
1+
import peg from 'peggy';
22
import { MfmNode, MfmPlainNode } from './node';
33
import { stringifyNode, stringifyTree, inspectOne } from './util';
44

Diff for: src/parser.pegjs

+16-47
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,6 @@ inline
116116
/ fnVer1
117117
/ inlineText
118118

119-
inlineWithoutFn
120-
= emojiCode
121-
/ unicodeEmoji
122-
/ big
123-
/ bold
124-
/ small
125-
/ italic
126-
/ strike
127-
/ inlineCode
128-
/ mathInline
129-
/ mention
130-
/ hashtag
131-
/ url
132-
/ link
133-
/ inlineText
134-
135119
plain
136120
= emojiCode
137121
/ unicodeEmoji
@@ -357,21 +341,15 @@ hashtag
357341
}
358342

359343
hashtagContent
360-
= hashtagChar+ { return text(); }
361-
362-
hashtagChar
363-
= ![  \t.,!?'"#:\/【】] CHAR
364-
365-
// hashtagContent
366-
// = (hashtagBracketPair / hashtagChar)+ { return text(); }
344+
= (hashtagBracketPair / hashtagChar)+ { return text(); }
367345

368-
// hashtagBracketPair
369-
// = "(" hashtagContent* ")"
370-
// / "[" hashtagContent* "]"
371-
// / "「" hashtagContent* "」"
346+
hashtagBracketPair
347+
= "(" hashtagContent* ")"
348+
/ "[" hashtagContent* "]"
349+
/ "「" hashtagContent* "」"
372350

373-
// hashtagChar
374-
// = ![  \t.,!?'"#:\/\[\]【】()「」] CHAR
351+
hashtagChar
352+
= ![  \t.,!?'"#:\/\[\]【】()「」] CHAR
375353

376354
// inline: URL
377355

@@ -395,17 +373,13 @@ urlContent
395373
= urlContentPart+
396374

397375
urlContentPart
398-
= [.,] &urlContentPart // last char is neither "." nor ",".
376+
= urlBracketPair
377+
/ [.,] &urlContentPart // last char is neither "." nor ",".
399378
/ [a-z0-9_/:%#@$&?!~=+-]i
400379

401-
// urlContentPart
402-
// = urlBracketPair
403-
// / [.,] &urlContentPart // last char is neither "." nor ",".
404-
// / [a-z0-9_/:%#@$&?!~=+-]i
405-
406-
// urlBracketPair
407-
// = "(" urlContentPart* ")"
408-
// / "[" urlContentPart* "]"
380+
urlBracketPair
381+
= "(" urlContentPart* ")"
382+
/ "[" urlContentPart* "]"
409383

410384
// inline: link
411385

@@ -419,17 +393,12 @@ linkLabel
419393
= parts:linkLabelPart+
420394
{
421395
return parts;
422-
//return parts.flat(Infinity);
423396
}
424397

425-
// linkLabelPart
426-
// = url { return text(); /* text node */ }
427-
// / link { return text(); /* text node */ }
428-
// / !"]" n:inline { return n; }
429-
430398
linkLabelPart
431-
// = "[" linkLabelPart* "]"
432-
= !"]" p:plain { return p; }
399+
= url { return text(); /* text node */ }
400+
/ link { return text(); /* text node */ }
401+
/ !"]" n:inline { return n; }
433402

434403
linkUrl
435404
= url { return text(); }
@@ -471,7 +440,7 @@ fnArg
471440
}
472441

473442
fnContentPart
474-
= !("]") i:inlineWithoutFn { return i; }
443+
= !("]") i:inline { return i; }
475444

476445
// inline: text
477446

Diff for: test/parser.ts

+33-36
Original file line numberDiff line numberDiff line change
@@ -638,18 +638,17 @@ describe('FullParser', () => {
638638
assert.deepStrictEqual(mfm.parse(input), output);
639639
});
640640

641-
// disabled
642-
// it('do not yield link node even if label is recognisable as a link', () => {
643-
// const input = 'official instance: [[https://misskey.io/@ai](https://misskey.io/@ai)](https://misskey.io/@ai).';
644-
// const output = [
645-
// TEXT('official instance: '),
646-
// LINK(false, 'https://misskey.io/@ai', [
647-
// TEXT('[https://misskey.io/@ai](https://misskey.io/@ai)')
648-
// ]),
649-
// TEXT('.')
650-
// ];
651-
// assert.deepStrictEqual(mfm.parse(input), output);
652-
// });
641+
it('do not yield link node even if label is recognisable as a link', () => {
642+
const input = 'official instance: [[https://misskey.io/@ai](https://misskey.io/@ai)](https://misskey.io/@ai).';
643+
const output = [
644+
TEXT('official instance: '),
645+
LINK(false, 'https://misskey.io/@ai', [
646+
TEXT('[https://misskey.io/@ai](https://misskey.io/@ai)')
647+
]),
648+
TEXT('.')
649+
];
650+
assert.deepStrictEqual(mfm.parse(input), output);
651+
});
653652
});
654653

655654
describe('fn v1', () => {
@@ -673,18 +672,17 @@ describe('FullParser', () => {
673672
assert.deepStrictEqual(mfm.parse(input), output);
674673
});
675674

676-
// fn nest is disabled
677-
// it('nest', () => {
678-
// const input = '[spin.speed=1.1s [shake a]]';
679-
// const output = [
680-
// FN('spin', { speed: '1.1s' }, [
681-
// FN('shake', { }, [
682-
// TEXT('a')
683-
// ])
684-
// ])
685-
// ];
686-
// assert.deepStrictEqual(mfm.parse(input), output);
687-
// });
675+
it('nest', () => {
676+
const input = '[spin.speed=1.1s [shake a]]';
677+
const output = [
678+
FN('spin', { speed: '1.1s' }, [
679+
FN('shake', { }, [
680+
TEXT('a')
681+
])
682+
])
683+
];
684+
assert.deepStrictEqual(mfm.parse(input), output);
685+
});
688686
});
689687

690688
describe('fn v2', () => {
@@ -708,18 +706,17 @@ describe('FullParser', () => {
708706
assert.deepStrictEqual(mfm.parse(input), output);
709707
});
710708

711-
// fn nest is disabled
712-
// it('nest', () => {
713-
// const input = '$[spin.speed=1.1s $[shake a]]';
714-
// const output = [
715-
// FN('spin', { speed: '1.1s' }, [
716-
// FN('shake', { }, [
717-
// TEXT('a')
718-
// ])
719-
// ])
720-
// ];
721-
// assert.deepStrictEqual(mfm.parse(input), output);
722-
// });
709+
it('nest', () => {
710+
const input = '$[spin.speed=1.1s $[shake a]]';
711+
const output = [
712+
FN('spin', { speed: '1.1s' }, [
713+
FN('shake', { }, [
714+
TEXT('a')
715+
])
716+
])
717+
];
718+
assert.deepStrictEqual(mfm.parse(input), output);
719+
});
723720
});
724721

725722
it('composite', () => {

0 commit comments

Comments
 (0)