memos icon indicating copy to clipboard operation
memos copied to clipboard

Markdown hyperlinks with parenthesis in take first closing parenthesis as final

Open nickcowans opened this issue 2 years ago • 6 comments

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

  1. Paste [Severance](https://en.wikipedia.org/wiki/Severance_(TV_series)) into a memo
  2. Click Save
  3. Click on the created link, it will be to "https://en.wikipedia.org/wiki/Severance_(TV_series"

Screenshots or additional context

No response

nickcowans avatar Feb 25 '23 22:02 nickcowans

+1

also [ [paper](https://arxiv.org/abs/2112.10752) ] renders as [paper ] which looks to be a similar issue

HappyZ avatar Feb 27 '23 09:02 HappyZ

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

HappyZ avatar Feb 27 '23 10:02 HappyZ

Changing the regex here to /\[(.*?)\]\((.+?)\)$/ also fixes things

TheRealJd3 avatar Feb 27 '23 21:02 TheRealJd3

for my own curiosity how does the parser work for single line string containing multiple links?

HappyZ avatar Feb 27 '23 21:02 HappyZ

It doesn't handle them - good point !

TheRealJd3 avatar Feb 27 '23 22:02 TheRealJd3

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

HappyZ avatar Feb 27 '23 23:02 HappyZ

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

boojack avatar Mar 01 '23 14:03 boojack