Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
🐛 The regular expression for determing text that is bold was greedy
Browse files Browse the repository at this point in the history
One of the problems at GitHub that we saw when rending a markdown file
with some code blocks is that when there was an unclosed block, it will
highlight the rest of the remaining text as bold, overriding any
highlights that should take effect.

This test change is based on a refactoring that was done to group
together the patterns and also change the regex for bold to match the
one used in `burodepeper/language-markdown` which is also an atom
package for syntax highlighting
  • Loading branch information
nickborromeo committed Jun 2, 2020
1 parent 8e5a9d4 commit a79c436
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions spec/gfm-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,19 @@ describe "GitHub Flavored Markdown grammar", ->

it "tokenizes **bold** text", ->
{tokens} = grammar.tokenizeLine("**bold**")
expect(tokens[0]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[0]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm", "punctuation.definition.entity.gfm"]
expect(tokens[1]).toEqual value: "bold", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[2]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[2]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm", "punctuation.definition.entity.gfm"]

[firstLineTokens, secondLineTokens] = grammar.tokenizeLines("this is **bo\nld**!")
expect(firstLineTokens[0]).toEqual value: "this is ", scopes: ["source.gfm"]
expect(firstLineTokens[1]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm"]
expect(firstLineTokens[2]).toEqual value: "bo", scopes: ["source.gfm", "markup.bold.gfm"]
expect(secondLineTokens[0]).toEqual value: "ld", scopes: ["source.gfm", "markup.bold.gfm"]
expect(secondLineTokens[1]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm"]
expect(secondLineTokens[2]).toEqual value: "!", scopes: ["source.gfm"]
[firstLineTokens, secondLineTokens] = grammar.tokenizeLines("this is **not\nbold**!")
expect(firstLineTokens[0]).toEqual value: "this is **not", scopes: ["source.gfm"]
expect(secondLineTokens[0]).toEqual value: "bold**!", scopes: ["source.gfm"]

{tokens} = grammar.tokenizeLine("not**bold**")
expect(tokens[0]).toEqual value: "not**bold**", scopes: ["source.gfm"]
expect(tokens[0]).toEqual value: "not", scopes: ["source.gfm"]
expect(tokens[1]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm", "punctuation.definition.entity.gfm"]
expect(tokens[2]).toEqual value: "bold", scopes: ["source.gfm", "markup.bold.gfm"]
expect(tokens[3]).toEqual value: "**", scopes: ["source.gfm", "markup.bold.gfm", "punctuation.definition.entity.gfm"]

it "tokenizes __bold__ text", ->
{tokens} = grammar.tokenizeLine("____")
Expand Down

0 comments on commit a79c436

Please sign in to comment.