Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Jun 5, 2021
2 parents 2163d38 + 229eb1e commit 11a763f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 89 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "mfm-js",
"version": "0.16.4",
"version": "0.16.5",
"description": "An MFM parser implementation with PEG.js",
"main": "./built/index.js",
"types": "./built/index.d.ts",
"scripts": {
"build": "npm run tsc && npm run peg",
"build-debug": "npm run tsc && npm run peg-debug",
"peg": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser.pegjs",
"peg-debug": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser.pegjs",
"peg": "peggy --cache -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser.pegjs",
"peg-debug": "peggy --cache -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser.pegjs",
"tsc": "tsc",
"tsd": "tsd",
"parse": "node ./built/cli/parse",
Expand All @@ -24,9 +24,8 @@
"devDependencies": {
"@types/mocha": "8.2.x",
"@types/node": "14.14.x",
"@types/pegjs": "0.10.x",
"mocha": "8.3.x",
"pegjs": "0.10.x",
"peggy": "1.2.0",
"ts-node": "9.1.x",
"tsd": "^0.14.0",
"typescript": "4.2.x"
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import peg from 'pegjs';
import peg from 'peggy';
import { MfmNode, MfmPlainNode } from './node';
import { stringifyNode, stringifyTree, inspectOne } from './util';

Expand Down
63 changes: 16 additions & 47 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,6 @@ inline
/ fnVer1
/ inlineText

inlineWithoutFn
= emojiCode
/ unicodeEmoji
/ big
/ bold
/ small
/ italic
/ strike
/ inlineCode
/ mathInline
/ mention
/ hashtag
/ url
/ link
/ inlineText

plain
= emojiCode
/ unicodeEmoji
Expand Down Expand Up @@ -357,21 +341,15 @@ hashtag
}

hashtagContent
= hashtagChar+ { return text(); }

hashtagChar
= ![  \t.,!?'"#:\/【】] CHAR

// hashtagContent
// = (hashtagBracketPair / hashtagChar)+ { return text(); }
= (hashtagBracketPair / hashtagChar)+ { return text(); }

// hashtagBracketPair
// = "(" hashtagContent* ")"
// / "[" hashtagContent* "]"
// / "「" hashtagContent* "」"
hashtagBracketPair
= "(" hashtagContent* ")"
/ "[" hashtagContent* "]"
/ "「" hashtagContent* "」"

// hashtagChar
// = ![  \t.,!?'"#:\/\[\]【】()「」] CHAR
hashtagChar
= ![  \t.,!?'"#:\/\[\]【】()「」] CHAR

// inline: URL

Expand All @@ -395,17 +373,13 @@ urlContent
= urlContentPart+

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

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

// urlBracketPair
// = "(" urlContentPart* ")"
// / "[" urlContentPart* "]"
urlBracketPair
= "(" urlContentPart* ")"
/ "[" urlContentPart* "]"

// inline: link

Expand All @@ -419,17 +393,12 @@ linkLabel
= parts:linkLabelPart+
{
return parts;
//return parts.flat(Infinity);
}

// linkLabelPart
// = url { return text(); /* text node */ }
// / link { return text(); /* text node */ }
// / !"]" n:inline { return n; }

linkLabelPart
// = "[" linkLabelPart* "]"
= !"]" p:plain { return p; }
= url { return text(); /* text node */ }
/ link { return text(); /* text node */ }
/ !"]" n:inline { return n; }

linkUrl
= url { return text(); }
Expand Down Expand Up @@ -471,7 +440,7 @@ fnArg
}

fnContentPart
= !("]") i:inlineWithoutFn { return i; }
= !("]") i:inline { return i; }

// inline: text

Expand Down
69 changes: 33 additions & 36 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,18 +638,17 @@ describe('FullParser', () => {
assert.deepStrictEqual(mfm.parse(input), output);
});

// disabled
// it('do not yield link node even if label is recognisable as a link', () => {
// const input = 'official instance: [[https://misskey.io/@ai](https://misskey.io/@ai)](https://misskey.io/@ai).';
// const output = [
// TEXT('official instance: '),
// LINK(false, 'https://misskey.io/@ai', [
// TEXT('[https://misskey.io/@ai](https://misskey.io/@ai)')
// ]),
// TEXT('.')
// ];
// assert.deepStrictEqual(mfm.parse(input), output);
// });
it('do not yield link node even if label is recognisable as a link', () => {
const input = 'official instance: [[https://misskey.io/@ai](https://misskey.io/@ai)](https://misskey.io/@ai).';
const output = [
TEXT('official instance: '),
LINK(false, 'https://misskey.io/@ai', [
TEXT('[https://misskey.io/@ai](https://misskey.io/@ai)')
]),
TEXT('.')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});

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

// fn nest is disabled
// it('nest', () => {
// const input = '[spin.speed=1.1s [shake a]]';
// const output = [
// FN('spin', { speed: '1.1s' }, [
// FN('shake', { }, [
// TEXT('a')
// ])
// ])
// ];
// assert.deepStrictEqual(mfm.parse(input), output);
// });
it('nest', () => {
const input = '[spin.speed=1.1s [shake a]]';
const output = [
FN('spin', { speed: '1.1s' }, [
FN('shake', { }, [
TEXT('a')
])
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});

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

// fn nest is disabled
// it('nest', () => {
// const input = '$[spin.speed=1.1s $[shake a]]';
// const output = [
// FN('spin', { speed: '1.1s' }, [
// FN('shake', { }, [
// TEXT('a')
// ])
// ])
// ];
// assert.deepStrictEqual(mfm.parse(input), output);
// });
it('nest', () => {
const input = '$[spin.speed=1.1s $[shake a]]';
const output = [
FN('spin', { speed: '1.1s' }, [
FN('shake', { }, [
TEXT('a')
])
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});

it('composite', () => {
Expand Down

0 comments on commit 11a763f

Please sign in to comment.