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

Merge branch 'develop' into master

parents 54a4c457 a53071dd
No related branches found
No related tags found
No related merge requests found
{
"name": "mfm-js",
"version": "0.12.0",
"version": "0.0.0",
"description": "An MFM parser implementation with PEG.js",
"main": "./built/index.js",
"types": "./built/index.d.ts",
......
......@@ -333,7 +333,7 @@ urlBracketPair
// inline: link
link
= silent:"?"? "[" label:linkLabel "](" url:linkUrl ")"
= silent:"?"? "[" label:linkLabelPart+ "](" url:linkUrl ")"
{
return createNode('link', {
silent: (silent != null),
......@@ -341,8 +341,10 @@ link
}, mergeText(label));
}
linkLabel
= (!"]" n:inline { return n; })+
linkLabelPart
= url { return text(); /* text node */ }
/ link { return text(); /* text node */ }
/ !"]" n:inline { return n; }
linkUrl
= url { return text(); }
......@@ -382,7 +384,7 @@ fnArg
// inline: text
text
= .
= . /* text node */
//
// General
......
......@@ -2,7 +2,7 @@ import assert from 'assert';
import { extract, inspect, parse, parsePlain, toString } from '../built/index';
import { createNode } from '../built/util';
import {
TEXT, CENTER, FN, UNI_EMOJI, MENTION, EMOJI_CODE, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK
TEXT, CENTER, FN, UNI_EMOJI, MENTION, EMOJI_CODE, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK, LINK
} from './node';
describe('text', () => {
......@@ -423,7 +423,53 @@ describe('url', () => {
});
});
// link
describe('link', () => {
it('basic', () => {
const input = '[official instance](https://misskey.io/@ai).';
const output = [
LINK(false, 'https://misskey.io/@ai', [
TEXT('official instance')
]),
TEXT('.')
];
assert.deepStrictEqual(parse(input), output);
});
it('silent flag', () => {
const input = '?[official instance](https://misskey.io/@ai).';
const output = [
LINK(true, 'https://misskey.io/@ai', [
TEXT('official instance')
]),
TEXT('.')
];
assert.deepStrictEqual(parse(input), output);
});
it('do not yield url node even if label is recognisable as a url', () => {
const input = 'official instance: [https://misskey.io/@ai](https://misskey.io/@ai).';
const output = [
TEXT('official instance: '),
LINK(false, 'https://misskey.io/@ai', [
TEXT('https://misskey.io/@ai')
]),
TEXT('.')
];
assert.deepStrictEqual(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(parse(input), output);
});
});
describe('fn', () => {
it('basic', () => {
......@@ -497,10 +543,20 @@ describe('inspect API', () => {
describe('extract API', () => {
it('basic', () => {
const nodes = parse('abc:hoge:[tada 123:hoge:]:piyo:');
const nodes = parse('@hoge @piyo @bebeyo');
const expect = [
MENTION('hoge', null, '@hoge'),
MENTION('piyo', null, '@piyo'),
MENTION('bebeyo', null, '@bebeyo')
];
assert.deepStrictEqual(extract(nodes, 'mention'), expect);
});
it('nested', () => {
const nodes = parse('abc:hoge:[tada 123 @hoge :foo:]:piyo:');
const expect = [
EMOJI_CODE('hoge'),
EMOJI_CODE('hoge'),
EMOJI_CODE('foo'),
EMOJI_CODE('piyo')
];
assert.deepStrictEqual(extract(nodes, 'emojiCode'), expect);
......
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