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

Markdown links containing [ and ] are broken #112

Open
RagnarGrootKoerkamp opened this issue Aug 29, 2019 · 4 comments
Open

Markdown links containing [ and ] are broken #112

RagnarGrootKoerkamp opened this issue Aug 29, 2019 · 4 comments

Comments

@RagnarGrootKoerkamp
Copy link

The library doesn't allow [ and ] inside a markdown link text to occur, while the spec allows:

  • matching, unescaped [ and ]
  • escaped \[ and \].

(I came here via https://gitlab.com/gitlab-org/gitlab-ce/issues/66601, where the formatting of commit messages is broken when the message includes [ and ]. I'd try to solve it on the gitlab side, but that's only possible when escaped brackets are picked up correctly.)

@stevebissett
Copy link

@RagnarGrootKoerkamp - Did you come up with a solution for this. I am also having this issue at the moment.

@RagnarGrootKoerkamp
Copy link
Author

https://gitlab.com/gitlab-org/gitlab/-/issues/31263#note_215961096
That fixed it for me at the time: I just create slack formatted links directly in gitlab instead of having markdown links converted to slack links at a later point.

Not sure if it still works though; I lost those local changes after updating and didn't bother to make them again.

@RagnarGrootKoerkamp
Copy link
Author

Here's a page explaining a general regex for matching links in markdown: https://medium.com/@michael_perrin/match-markdown-links-with-advanced-regex-features-fc5f9f4122bc

It uses the following for matching the [..] part:

(?<text_group>                  # Text group, including square brackets
  \[
    (?>                         # (?> defines an atomic group, this is a performance improvement when using recursion
      [^\[\]]+                  # Look for any char except closing square bracket
      |(?&text_group)           # OR: find recursively an other pattern with opening and closing square brackets
    )*
  \]
)

I'd hope that putting that bit of code here should do the trick.

I'd do it myself but don't have any Ruby experience. Maybe you can test it and create a PR @stevebissett

@stevebissett
Copy link

Thanks @RagnarGrootKoerkamp - I landed up working around this by going the conversion before using the Slack formatter, because it was easy to do so in my use case.

I did have a go at trying to adjust the regex's and markdown handling to support this but I haven't managed to find working code that makes the spec pass. I am not all that familiar with Regex's at this complexity.

I have pushed up a spec for it here:
#120

I did have a look at some other Ruby markdown converters like redcarpet and the RDoc markdown to try and get a better idea of some alternative approaches but didn't come right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants