[MFM] Better inline code parse
This commit is contained in:
parent
b7b36973f7
commit
b2f8003602
|
@ -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
|
||||
|
||||
|
|
18
test/mfm.ts
18
test/mfm.ts
|
@ -469,13 +469,29 @@ describe('Text', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('inline code', () => {
|
||||
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', () => {
|
||||
const fomula = 'x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}';
|
||||
const text = `\\(${fomula}\\)`;
|
||||
|
|
Loading…
Reference in New Issue