text icon indicating copy to clipboard operation
text copied to clipboard

Escaping of square brackets breaks links of embedded attachments for external Markdown Editor

Open chrda81 opened this issue 1 year ago • 20 comments

Short summary of the issue

I'm using an external Markdown Editor (Obsidian) and sync the files via the NextCloud Desktop Client to the server. When saving a markdown file with the NextCloud text editor in the web interface, the links for embedded attachements are broken, because the square brackets are escaped with a backslash. Can this escaping for square brackets (or other chars) manually turned off?

  • [ ] Markdown syntax is not properly rendered in text
  • [ ] Markdown syntax is removed after closing text
  • [x] Markdown syntax is changed after closing text
  • [ ] Something else: Please describe more in detail

Example markdown content

![[Pasted image 20230908203759.png]]

Resulting markdown content after saving

!\[\[Pasted image 20230908203759.png\]\]

Screenshot of the rendering in text

image

Details

  • Nextcloud version: Nextcloud AIO v7.1.1

chrda81 avatar Sep 14 '23 12:09 chrda81

Thanks for the report. Can you tell how Obsidian renders this? Is it just a regular image element with a relative path to the image?

juliusknorr avatar Sep 14 '23 12:09 juliusknorr

Yes, this embedded attachment is put as separate file besides the markdown file and is rendered as image element. Of course, it would be brilliant if the NextCloud text editor could also render these ;)

chrda81 avatar Sep 14 '23 12:09 chrda81

Kind of related to https://github.com/nextcloud/text/issues/1065 but while i commented back then I feel less hesitant to add those if we just cover them to preserve syntax for now.

This would need a few steps though:

  • [ ] Figure out a way to extend markdown-it to properly handle wikilink style links and images
  • [ ] Make sure that the used syntax is persistent during editing in the tiptap nodes
  • [ ] Properly write back markdown depending on the current syntax

Most relevant spec for Obsidian is this one https://help.obsidian.md/Linking+notes+and+files/Embedding+files

As a side note: I kind of like this syntax for "embedding files or links". This could also be interesting to separate a bit more between link previews and parts where people actually want to embed the file content (like a pdf that is rendered inline) - though that is probably something for a different discussion.

juliusknorr avatar Sep 14 '23 14:09 juliusknorr

@max-nextcloud @mejo- Any thoughts or objections on adding support for that syntax?

juliusknorr avatar Sep 14 '23 14:09 juliusknorr

No objections at all. I actually like the syntax and the distinction between embedded content and links. First of all I think we should make sure not to mess with the syntax.

max-nextcloud avatar Sep 15 '23 11:09 max-nextcloud

I noticed the same issue but for a different reason. I wanted to add a link to a website but with the link embedded in text. The markdown standard supports this in the following way: [Link](http://a.com) markdown website But as the issue says the "[" and "]" are escaped with a backslash in the nextcloud text editor and it does not work.

Is it possible to disable the escaping of this character? Or have an option in the menu to do this or using the smart picker, just some ideas.

Thanks!

Mat-DB avatar Oct 08 '23 19:10 Mat-DB

I noticed the same issue but for a different reason. I wanted to add a link to a website but with the link embedded in text. The markdown standard supports this in the following way: [Link](http://a.com) markdown website But as the issue says the "[" and "]" are escaped with a backslash in the nextcloud text editor and it does not work.

Is it possible to disable the escaping of this character? Or have an option in the menu to do this or using the smart picker, just some ideas.

Thanks!

This is likely a different topic. We already support []() links in the markdown source, just not during typing. Maybe you can open a separate issue for that.

You can already create such links through the menu when marking existing text.

juliusknorr avatar Oct 12 '23 12:10 juliusknorr

I think there is something else goin on here.... What would be the explanation for this? y\~

My original text was y~ along with some other password like characters.... Not a ( [ ] or ) in sight.... Or { } either for that matter... Unless starting a line with & is illegal?

sn0n avatar Feb 18 '24 08:02 sn0n

Maybe some xss filter trying to do its sanitation?

sn0n avatar Feb 18 '24 08:02 sn0n

Is there any workaround anyone has found? I'm using Obsidian too and it makes switching between editing in nextcloud and obsidian painful due to breaking all the links.

Is there a way to get raw editing or hook into file save to run my own cleanup script or something?

KFreon avatar Mar 27 '24 11:03 KFreon

Is there any workaround anyone has found? I'm using Obsidian too and it makes switching between editing in nextcloud and obsidian painful due to breaking all the links.

Is there a way to get raw editing or hook into file save to run my own cleanup script or something?

I used to use https://apps.nextcloud.com/apps/files_markdown. But it's a pita that NC decided to not allow to change the default away from texts.

I've also got this issue if I just want to share a note for viewing. It gets open in the text app and is broken.

Even if there is no support or exception for unsupported syntax, the app should not change the content if no input was made.

janLo avatar Apr 29 '24 23:04 janLo

I've ended up writing an Obsidian plugin to fix them. Looking to get it published to the Obsidian list for use.

KFreon avatar May 06 '24 05:05 KFreon

same for us with Logseq it doesnt make it 'hard' to work with any other markdown editor - it simply makes it impossible

trilium, joplin, obsidian, logseq may work on the same documents - just not NC

it's a pity to think of a plugin for each editor (as mentioned above) to work this problem around - as it's once again the users - people's work in other words - that is at stake instead of a technical response to teams' needs

it seems to be a general state of things at this erea: i work in state schools in France, students and teachers are highly limited in their work because of IT services decisions and processes - it seems that 'work' and ´usage' come after the ´tool' and its conception - i think its a break down to our investment in working with computers ..

good luck to everyone to build a better future for the collaboration of our human organisations 🙏✌️

punkyard avatar Jun 12 '24 12:06 punkyard

This originates from https://github.com/ProseMirror/prosemirror-markdown/blob/e59521463f62b296cc072962aa2d60b267ea4397/src/to_markdown.ts#L432-L443

I don't see a quick and easy way to adjust escaping directly

juliusknorr avatar Jun 13 '24 07:06 juliusknorr

It would be great to have at least the option to just open and view the file without having it destroyed. I don't need to edit it in NC but I like to view it and share a link.

janLo avatar Jun 20 '24 19:06 janLo

It would be great to have at least the option to just open and view the file

Well, can't you do this yet? by choosing the option of the action to perform when file is opened in Collectives: view or edit?

punkyard avatar Jun 20 '24 23:06 punkyard

It would be great to have at least the option to just open and view the file

Well, can't you do this yet? by choosing the option of the action to perform when file is opened in Collectives: view or edit?

As soon as I click on it it opens in the the editor and is broken 😕

janLo avatar Jun 21 '24 13:06 janLo

@janLo then you might have to think of a different way to publish your notes, and view them or edit them on line.

Have you had to disable wikilinks in Obsidian? aren't the wikilinks preserved by the NC editor?

punkyard avatar Jun 21 '24 14:06 punkyard

No solution to this?

jannikgade avatar Jul 01 '24 12:07 jannikgade

No solution to this?

not on my side :/

punkyard avatar Jul 01 '24 14:07 punkyard