Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parenthesis after links in markdown lexer #1449

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Ravlen
Copy link
Contributor

@Ravlen Ravlen commented Mar 4, 2020

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 Ravlen changed the title Fix parenthese after links in markdown lexer Fix parenthesis after links in markdown lexer Mar 4, 2020
@pyrmont pyrmont self-assigned this Mar 4, 2020
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Mar 4, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Mar 25, 2020

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

@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Mar 25, 2020
@Ravlen
Copy link
Contributor Author

Ravlen commented Mar 25, 2020

@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

@pyrmont pyrmont force-pushed the ravlen.bugfix.markdown-link-parens branch from ffe07cb to 765a65f Compare April 14, 2020 10:00
@pyrmont
Copy link
Contributor

pyrmont commented Apr 14, 2020

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

@Ravlen
Copy link
Contributor Author

Ravlen commented Apr 16, 2020

@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

push :url
end

# links and images
rule %r/(!?\[)(#{edot}*?|[^\]]*?)(\])(?=[\[(])/ do
rule %r/(!?\[)((?:\\.|[^\\\]]|`.*?`)*?)(\])(?=[\[(])/ do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ravlen This is the bit I'm unhappy about. It feels like a gross hack to allow the use of [[ and ]] for TOML headings but I couldn't see another way to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pyrmont FYI, don't feel like you have to merge this right away, I'm just swamped at work. When I get some free time I fully intend to come back to this and see if I can come up with an alternative. 🙇

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 As someone coming to this way late, I'm not quite sure what the concern is about the TOML headings. @Ravlen any insights? Is the concern it's syntactically incorrect, or the Regex is nasty?

@Ravlen
Copy link
Contributor Author

Ravlen commented Aug 23, 2020

@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... 🙇

@pyrmont pyrmont removed their assignment Dec 9, 2020
Copy link
Collaborator

@dblessing dblessing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ravlen I ran through some debugging on this and it looks OK to me. Please let me know if there are any concerns I'm not seeing about the TOML bit @pyrmont brought up. Otherwise, let's merge.

push :url
end

# links and images
rule %r/(!?\[)(#{edot}*?|[^\]]*?)(\])(?=[\[(])/ do
rule %r/(!?\[)((?:\\.|[^\\\]]|`.*?`)*?)(\])(?=[\[(])/ do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 As someone coming to this way late, I'm not quite sure what the concern is about the TOML headings. @Ravlen any insights? Is the concern it's syntactically incorrect, or the Regex is nasty?


rule %r/[ \t]+/, Text
rule %r/[ \t]+/, Text, :title
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pre-existing, but I wonder why this used _\t here instead of \s which would cover all whitespace (underscore used to emphasize literal space).

@tancnle
Copy link
Collaborator

tancnle commented Sep 22, 2021

@Ravlen @dblessing Look like this is mergeable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author-action The PR has been reviewed but action by the author is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edge case in markdown lexer regarding links followed by parens
4 participants