bmoliveira / MarkdownKit

A simple and customizable Markdown Parser for Swift
MIT License
783 stars 136 forks source link

Links and parentheses don't work well together #78

Closed AndreasVerhoeven closed 3 years ago

AndreasVerhoeven commented 3 years ago

([linkme](schema://domain/whees)) results in (linkme -> schema://domain/whees) where one would expect (linkme) -> schema://domain/whees.

This can be fixed by making the link regex not greedy. The downside is that embedded parentheses in links will not be parsed correctly.

Another approach is to try to balance the bracket: any closing bracket at the end of the link that's is not matched by an opening bracket will be assumed to outside of the actual link. This heuristic seems to work well in practice. I've made a PR for this (https://github.com/bmoliveira/MarkdownKit/pull/79).

Before (notice how the first linkme is broken):

Screenshot 2021-02-02 at 22 49 34

After (notice how all links now work correctly):

Screenshot 2021-02-02 at 22 50 22