marked icon indicating copy to clipboard operation
marked copied to clipboard

Code blocks must be left intact

Open fredck opened this issue 4 years ago • 3 comments

Describe the bug
Code blocks are very controlled content, where the author has intent (and full responsibility) on everything inside it. Right now, tabs inside code blocks are replaced by 4 spaces. This is (probably in most of the cases) semantically incorrect.

To Reproduce
Steps to reproduce the behavior:

  1. Marked Demo
  2. CommonMark Demo

Expected behavior
The contents of the code block should be left intact (tabs untouched).


Many times, code in a document is used as an example or reference to be copied/pasted or used "as is". Marked is not aware of the purpose of the code, so it should not take action on it and leave it intact.

This is a real world example of this problem: ckeditor/github-writer#170. The code block is a suggestion for changes to source code and they can be merged as the author wrote it. Marked is changing the code though and, basically, breaking the author contribution.

I can imagine this being a problem on many other contexts as well.


I've seen similar issues here for the same problem. Most of them are not clear and mainly closed. I wanted to refresh this problem with this issue.

fredck avatar May 08 '20 09:05 fredck

Similar to #1559

UziTech avatar May 08 '20 15:05 UziTech

It looks like this has been fixed since 4.0.14

azmy60 avatar May 20 '23 14:05 azmy60

Not completely, lines in code blocks that start with tabs are still converted to spaces. demo

UziTech avatar May 24 '23 03:05 UziTech