Changes
3 changed files (+59/-15)
-
-
@@ -42,7 +42,7 @@ parseText) => { const prevChar = text.charAt(position - 1) if (prevChar && !prevChar.match(/\s/)) { if (prevChar && !prevChar.match(/[\s.,([{!?\-=]/)) { return null }
-
-
-
@@ -4,7 +4,7 @@ import { explicit, or, regexp, topOfLine } from './combinator'const parseBold = explicit( regexp( /^\*(\S([^*\n]*?|[^*\n]*? `.*?` )\S|\S)\*(?=[\s.,]|$)/, /^\*(\S([^*\n]*?|[^*\n]*? `.*?` )\S|\S)\*(?=[\s.,\])}!?\-=]|$)/, (match, text, position, parseText) => { const [matchedText, content] = match
-
@@ -20,7 +20,7 @@ )) const parseCode = explicit( regexp(/^`([^`]+?)`(?=\s|$)/, (match, text, position) => { regexp(/^`([^`]+?)`(?=[\s.,\])}!?\-=]|$)/, (match, text, position) => { const [matchedText, content] = match return [
-
@@ -34,22 +34,25 @@ })) const parsePreText = explicit( regexp(/^```(\s*\S[\s\S]*?\s*)```(?=\s|$)/, (match, text, position) => { const [matchedText, content] = match regexp( /^```(\s*\S[\s\S]*?\s*)```(?=[\s.,\])}!?\-=]|$)/, (match, text, position) => { const [matchedText, content] = match return [ { type: NodeType.PreText, text: content }, position + matchedText.length ] }) return [ { type: NodeType.PreText, text: content }, position + matchedText.length ] } ) ) const parseItalic = explicit( regexp( /^_(\S([^_\n]*?|[^_\n]*? `.*?` )\S|\S)\_(?=[\s.,]|$)/, /^_(\S([^_\n]*?|[^_\n]*? `.*?` )\S|\S)\_(?=[\s.,\])}!?\-=]|$)/, (match, text, position, parseText) => { const [matchedText, content] = match
-
@@ -66,7 +69,7 @@ )const parseStrike = explicit( regexp( /^~(\S([^~\n]*?|[^~\n]*? `.*?` )\S|\S)\~(?=[\s.,]|$)/, /^~(\S([^~\n]*?|[^~\n]*? `.*?` )\S|\S)\~(?=[\s.,\])}!?\-=]|$)/, (match, text, position, parseText) => { const [matchedText, content] = match
-
-
-
@@ -206,6 +206,47 @@ expect(parse('>>>')).toEqual(root([quote([text('>>')])]))}) }) describe('Punctuations', () => { it('Should delimit with "?"', () => { expect(parse('*foo*?')).toEqual(root([bold([text('foo')]), text('?')])) }) it('Should delimit with "!"', () => { expect(parse('*foo*!')).toEqual(root([bold([text('foo')]), text('!')])) }) it('Should delimit with "."', () => { expect(parse('*foo*.')).toEqual(root([bold([text('foo')]), text('.')])) }) it('Should delimit with "()"', () => { expect(parse('(*foo*)')).toEqual( root([text('('), bold([text('foo')]), text(')')]) ) expect(parse(')*foo*(')).toEqual(root([text(')*foo*(')])) }) it('Should delimit with "[]"', () => { expect(parse('[*foo*]')).toEqual( root([text('['), bold([text('foo')]), text(']')]) ) expect(parse(']*foo*[')).toEqual(root([text(']*foo*[')])) }) it('Should delimit with "{}"', () => { expect(parse('{*foo*}')).toEqual( root([text('{'), bold([text('foo')]), text('}')]) ) expect(parse('}*foo*{')).toEqual(root([text('}*foo*{')])) }) it('Should delimit with "-" or "="', () => { expect(parse('-*foo*=')).toEqual( root([text('-'), bold([text('foo')]), text('=')]) ) }) }) describe('Root parser', () => { it('Should parse slack message', () => { const expected = root([
-