rouge icon indicating copy to clipboard operation
rouge copied to clipboard

Fix parenthesis after links in markdown lexer

Open Ravlen opened this issue 5 years ago • 6 comments

Fixes #1448

Currently, there is an odd edge case where a link followed by an open parenthesis triggers incorrect coloring: the last text should be uncolored, it's plaintext. (You can ignore the reference link in the screenshot, I was just making sure the code coloring was properly "different" for regular and referenced links):

Screen Shot 2020-03-04 at 14 59 57

When looking at the code, I couldn't understand why it was done as:

token Punctuation
push :inline_title
push :inline_url

It seemed to make sense to just do it the same as for link references:

rule %r/(\()(#{edot}*?)(\))/ do
  groups Punctuation, Str::Other, Punctuation
  pop!
end

and remove inline_title and inline_url. When removed, everything seemed to work as expected:

Screen Shot 2020-03-04 at 14 59 02

@pyrmont Could you take a look? I couldn't find any failures in the markdown sample file, but I might not be considering all the possibilities.

Ravlen avatar Mar 04 '20 06:03 Ravlen

@Ravlen What happens if the inline link has a title?

pyrmont avatar Mar 25 '20 06:03 pyrmont

@pyrmont Ahhhh. 😅

Screen Shot 2020-03-25 at 16 10 53

Ok, needs a little more work. 😁 Good catch! 🙇

FYI, Rouge dingus seems to have the best title text coloring:

Screen Shot 2020-03-25 at 16 00 16

In GitHub it's not great:

[This is not a link] (example.com)

[link is followed](example.com) (parentheses)
[link is followed](example.com) (paren theses)
[link is followed](example.com "Title text") paren (theses)

[This link is referenced][exampleref]
[exampleref]: http://example.com "Title text"

Strangely, in GitLab the Title text looks more like GitHub, even though it's using Rouge, must have selected no color for that item (Name.Namespace I guess).

Screen Shot 2020-03-25 at 16 03 35

Ravlen avatar Mar 25 '20 07:03 Ravlen

@Ravlen I made a couple of changes. What do you think?

pyrmont avatar Apr 14 '20 20:04 pyrmont

@pyrmont Wow, that was a lot more work than I expected was required, sorry for the hassle! I pulled your commits and tested it now, and looks fantastic, thanks a lot! I also see my multi-line link fix is working too, glad it didn't break anything!

Screen Shot 2020-04-16 at 23 25 45

Ravlen avatar Apr 16 '20 14:04 Ravlen

@pyrmont Sorry for not replying here sooner... I've tried to come up with some recursive bracket matching algorithm that would work without need specific exceptions to make TOML work, but I just don't have the skill yet. I still hope to find the time to research this more, learn more about Rouge so I can start making better contributions, but things just have just continued to get busier.

For now, I think this is the best I can hope for, and I think we can merge this to at least get it rendering well, and I'll try to revisit if work ever lets up... 🙇

Ravlen avatar Aug 23 '20 23:08 Ravlen

@Ravlen @dblessing Look like this is mergeable?

tancnle avatar Sep 22 '21 12:09 tancnle