From 12aa24d354f9a3673e084d988a4f61fa484dc9f0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 21 Nov 2018 12:55:15 +0900 Subject: [PATCH] [MFM] Better inline code parse --- src/mfm/parser.ts | 2 +- test/mfm.ts | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts index 3831a86aa..5acba7867 100644 --- a/src/mfm/parser.ts +++ b/src/mfm/parser.ts @@ -119,7 +119,7 @@ const mfm = P.createLanguage({ //#region Inline code inlineCode: r => - P.regexp(/`(.+?)`/, 1) + P.regexp(/`([^´\n]+?)`/, 1) .map(x => makeNode('inlineCode', { code: x })), //#endregion diff --git a/test/mfm.ts b/test/mfm.ts index 0f878ea9b..d99bb2bac 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -469,11 +469,27 @@ describe('Text', () => { }); }); - it('inline code', () => { - const tokens = analyze('`var x = "Strawberry Pasta";`'); - assert.deepEqual([ - node('inlineCode', { code: 'var x = "Strawberry Pasta";' }) - ], tokens); + describe('inline code', () => { + it('simple', () => { + const tokens = analyze('`var x = "Strawberry Pasta";`'); + assert.deepEqual([ + 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', () => {