streetwriters / notesnook

A fully open source & end-to-end encrypted note taking alternative to Evernote.
https://notesnook.com/
GNU General Public License v3.0
9.56k stars 588 forks source link

Copy as markdown breaks formatting. So does copying/exporting as text #6336

Open CarlSinclair opened 1 month ago

CarlSinclair commented 1 month ago

What happened?

Copy as markdown

Since exporting as markdown is still paywalled (see #6292), copy as markdown is a satisfactory alternative. Problem is, it doesn't work correctly. It adds \, <, and >, seemingly for escaping, which ultimately breaks the markdown formatting. Here's an example:

### header
[text](link)

becomes

\### header
[text](<link>)

The whole point of exporting/copying as markdown is to avoid having to manually go through the document again and reformat it using markdown. These extra characters mean I still have to do that, making it not very different from exporting/copying as regular text.

Copy/export as text

Speaking of text, that behaves very strangely. In instances where markdown has not been applied, it copies/exports it faithfully. But when it is applied, it seems to copy/export the rendered markdown, without the markdown formatting. For example:

### Header

becomes

Header

Links that have been rendered as markdown are copied as such:

[text](link)

becomes text[link]

Suggested solution

Personally, I don't think it's generally helpful or necessary to have markdown get rendered while you are typing. I feel it gets in the way and makes editing more difficult.

Joplin tackles this by offering a choice between 3 views: unrendered markdown, rendered markdown, and a side-by-side. In the unrendered view, markdown can be copied as is, which makes it work. This would fix many markdown related issues.

A simpler approach could be using unrendered markdown in edit mode, with a "preview" or "reading" button where you can see the rendered output. That's the most common implementation, even used here on GitHub. Google Docs does something similar by entering reading mode when you open a document, and editing it requires clicking the edit button to enter editing mode.

Steps to reproduce the problem

Copy as text Copy as markdown Export as markdown

Version

3.0.13-9019490-desktop

Platform/OS

Windows

Relevant log output

I observed this behavior on Windows. I haven't checked if it's consistent on other platforms.
CarlSinclair commented 1 month ago

The least breaking way I've found to export markdown is by copying it as markdown then manually removing all the \, >, and <. At least the links remain functionally intact.