Skip to content
Snippets Groups Projects
Commit 11a763f3 authored by marihachi's avatar marihachi
Browse files

Merge branch 'develop' into master

parents 2163d386 229eb1e4
No related branches found
Tags v0.17.0
No related merge requests found
{
"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",
......@@ -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"
......
import peg from 'pegjs';
import peg from 'peggy';
import { MfmNode, MfmPlainNode } from './node';
import { stringifyNode, stringifyTree, inspectOne } from './util';
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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(); }
......@@ -471,7 +440,7 @@ fnArg
}
fnContentPart
= !("]") i:inlineWithoutFn { return i; }
= !("]") i:inline { return i; }
// inline: text
......
......@@ -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', () => {
......@@ -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', () => {
......@@ -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', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment