dendronhq / dendron

The personal knowledge management (PKM) tool that grows as you do!
https://wiki.dendron.so
Apache License 2.0
6.75k stars 257 forks source link

Code blocks and spans in preview are html encoded #2301

Open alefteris opened 2 years ago

alefteris commented 2 years ago

Please select the area your bug applies to. (Multiple selections are Possible. You can leave blank if you're not sure.)

Describe the bug

Markdown code blocks and code spans, when previewed from dendron preview, are html encoded. So when copying code content from the preview, some characters are html encoded.

To Reproduce

Steps to reproduce the behavior:

  1. Create note with the following content (including the markdown fenced code block delimiters):
```
foo && bar
```

test `one < two` test.
  1. Open dendron preview for this note
  2. Copy and paste the contents of the markdown code blocks from the preview to another text editor.
  3. The text that have been pasted is html encoded:

    foo &amp;&amp; bar
    
    one &lt; two

Expected behavior

The text pasted should have been:

foo && bar

one < two

Desktop (please complete the following information)

kevinslin commented 2 years ago

Thanks for the report! We will add it to our backlog and try to prioritize a fix!

ghost commented 2 years ago

A possible option could be to add an onClickHandler, onto the code Sections that copy the true values into the clipboard.

ghost commented 2 years ago

So after some digging, I found the Possible problem lies with this part of the codebase.

https://github.com/dendronhq/dendron/blob/0dfc14e6af04fd6079ecb751b1c32379d85a1be0/packages/common-server/src/etc.ts#L142-L147

The inner HTML part that gets returned is HTML escaped before it gets cleaned.

Possibile solutions could be to check if the selection is inside a <pre><code></code></pre> element anf if true run an HTML unescape over it.