[MFM] Better inline code parse

This commit is contained in:
syuilo 2018-11-21 12:55:15 +09:00
parent b7b36973f7
commit b2f8003602
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 22 additions and 6 deletions

View file

@ -119,7 +119,7 @@ const mfm = P.createLanguage({
//#region Inline code //#region Inline code
inlineCode: r => inlineCode: r =>
P.regexp(/`(.+?)`/, 1) P.regexp(/`([^´\n]+?)`/, 1)
.map(x => makeNode('inlineCode', { code: x })), .map(x => makeNode('inlineCode', { code: x })),
//#endregion //#endregion

View file

@ -469,11 +469,27 @@ describe('Text', () => {
}); });
}); });
it('inline code', () => { describe('inline code', () => {
const tokens = analyze('`var x = "Strawberry Pasta";`'); it('simple', () => {
assert.deepEqual([ const tokens = analyze('`var x = "Strawberry Pasta";`');
node('inlineCode', { code: 'var x = "Strawberry Pasta";' }) assert.deepEqual([
], tokens); node('inlineCode', { code: 'var x = "Strawberry Pasta";' })
], tokens);
});
it('disallow line break', () => {
const tokens = analyze('`foo\nbar`');
assert.deepEqual([
text('`foo\nbar`')
], tokens);
});
it('disallow ´', () => {
const tokens = analyze('`foo´bar`');
assert.deepEqual([
text('`foo´bar`')
], tokens);
});
}); });
it('math', () => { it('math', () => {