memos
memos copied to clipboard
Markdown hyperlinks with parenthesis in take first closing parenthesis as final
Describe the bug
For example [Severance](https://en.wikipedia.org/wiki/Severance_(TV_series))
will create a link to "https://en.wikipedia.org/wiki/Severance_(TV_series", rather than "https://en.wikipedia.org/wiki/Severance_(TV_series)"
Steps to reproduce
- Paste
[Severance](https://en.wikipedia.org/wiki/Severance_(TV_series))
into a memo - Click Save
- Click on the created link, it will be to "https://en.wikipedia.org/wiki/Severance_(TV_series"
Screenshots or additional context
No response
+1
also [ [paper](https://arxiv.org/abs/2112.10752) ]
renders as [paper ] which looks to be a similar issue
maybe /\[([^[\]\n]+)\]\(([^\n]+)\)/g
for link extraction instead of /\[(.*?)\]\((.+?)\)+/
here: https://github.com/usememos/memos/blob/1847756ade10debffee6e4b00271700d41a805d3/web/src/labs/marked/parser/Link.tsx#L9
took a quick look at https://github.com/usememos/memos/blob/1847756ade10debffee6e4b00271700d41a805d3/web/src/labs/marked/parser/PlainLink.tsx#L3 ~and it doesn't look right either~. I'm thinking: /(https?:\/\/\S+)/g
ok [^ ] is \S
Changing the regex here to /\[(.*?)\]\((.+?)\)$/
also fixes things
for my own curiosity how does the parser work for single line string containing multiple links?
It doesn't handle them - good point !
Found https://stackoverflow.com/questions/67940820/how-to-extract-markdown-links-with-a-regex and modified to exclude /n as well: /\[([^][\n]+)\](\(((?:[^()\n]+|(?2))+)\))/g
this might work for both scenarios + multiple links in one string
Current frontend parser is very simple and mainly using to get tags from a raw content.
And we've planned a Markdown parser in Go. Very much looking forward to getting contributions. https://github.com/orgs/usememos/projects/5?pane=issue&itemId=16186604