Use lookbehind for whitespace before bold/italic text

This commit is contained in:
Kevin Sawicki
2013-06-12 14:43:14 -07:00
parent 0f4ad0bbf5
commit eeb2782700
2 changed files with 24 additions and 24 deletions

View File

@@ -11,24 +11,24 @@
'patterns': [
{
'match': '(?:^|\\s)(\\*\\*[^\\*]+\\*\\*)'
'match': '(?<=^|\\s)(\\*\\*[^\\*]+\\*\\*)'
'captures':
'1': 'name': 'markup.bold.gfm'
'0': 'name': 'markup.bold.gfm'
}
{
'match': '(?:^|\\s)(__[^_]+__)'
'match': '(?<=^|\\s)(__[^_]+__)'
'captures':
'1': 'name': 'markup.bold.gfm'
'0': 'name': 'markup.bold.gfm'
}
{
'match': '(?:^|\\s)(\\*[^\\*]+\\*)'
'match': '(?<=^|\\s)(\\*[^\\*]+\\*)'
'captures':
'1': 'name': 'markup.italic.gfm'
'0': 'name': 'markup.italic.gfm'
}
{
'match': '(?:^|\\s)(_[^_]+_)'
'match': '(?<=^|\\s)(_[^_]+_)'
'captures':
'1': 'name': 'markup.italic.gfm'
'0': 'name': 'markup.italic.gfm'
}
{
'begin': '^#{1,6}\\s+'

View File

@@ -22,23 +22,25 @@ describe "GitHub Flavored Markdown grammar", ->
it "tokenizes **bold** text", ->
{tokens} = grammar.tokenizeLine("this is **bold** text")
expect(tokens[0]).toEqual value: "this is", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: " ", scopes: ["source.gfm"]
expect(tokens[2]).toEqual value: "**bold**", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[3]).toEqual value: " text", scopes: ["source.gfm"]
expect(tokens[0]).toEqual value: "this is ", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: "**bold**", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[2]).toEqual value: " text", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("not**bold**")
expect(tokens[0]).toEqual value: "not**bold**", scopes: ["source.gfm"]
it "tokenizes **bold** text", ->
{tokens} = grammar.tokenizeLine(" ")
expect(tokens[0]).toEqual value: " ", scopes: ["source.gfm"]
it "tokenizes __bold__ text", ->
{tokens} = grammar.tokenizeLine("____")
expect(tokens[0]).toEqual value: "____", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("this is __bold__ text")
expect(tokens[0]).toEqual value: "this is", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: " ", scopes: ["source.gfm"]
expect(tokens[2]).toEqual value: "__bold__", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[3]).toEqual value: " text", scopes: ["source.gfm"]
expect(tokens[0]).toEqual value: "this is ", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: "__bold__", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[2]).toEqual value: " text", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("not__bold__")
expect(tokens[0]).toEqual value: "not__bold__", scopes: ["source.gfm"]
@@ -48,10 +50,9 @@ describe "GitHub Flavored Markdown grammar", ->
expect(tokens[0]).toEqual value: "**", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("this is *italic* text")
expect(tokens[0]).toEqual value: "this is", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: " ", scopes: ["source.gfm"]
expect(tokens[2]).toEqual value: "*italic*", scopes: ["source.gfm", "markup.italic.gfm"]
expect(tokens[3]).toEqual value: " text", scopes: ["source.gfm"]
expect(tokens[0]).toEqual value: "this is ", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: "*italic*", scopes: ["source.gfm", "markup.italic.gfm"]
expect(tokens[2]).toEqual value: " text", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("not*italic*")
expect(tokens[0]).toEqual value: "not*italic*", scopes: ["source.gfm"]
@@ -61,10 +62,9 @@ describe "GitHub Flavored Markdown grammar", ->
expect(tokens[0]).toEqual value: "__", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("this is _italic_ text")
expect(tokens[0]).toEqual value: "this is", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: " ", scopes: ["source.gfm"]
expect(tokens[2]).toEqual value: "_italic_", scopes: ["source.gfm", "markup.italic.gfm"]
expect(tokens[3]).toEqual value: " text", scopes: ["source.gfm"]
expect(tokens[0]).toEqual value: "this is ", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: "_italic_", scopes: ["source.gfm", "markup.italic.gfm"]
expect(tokens[2]).toEqual value: " text", scopes: ["source.gfm"]
{tokens} = grammar.tokenizeLine("not_italic_")
expect(tokens[0]).toEqual value: "not_italic_", scopes: ["source.gfm"]