Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.45k stars 319 forks source link

Starting the text with 4 white spaces or more turns the text into code block #428

Closed AHabes closed 2 years ago

AHabes commented 2 years ago

Describe the bug

The text typed after 4 white spaces (or more) automatically becomes a code block. Clicking on the code icon shifts the text left by two spaces.

To Reproduce

  1. Go to the editor named "Toolbar customization" in the demo page https://easy-markdown-editor.tk/
  2. Hit white space 4 times (or more) to start your text with at least 4 empty spaces.
  3. Start writing some text, the code option is automatically activated. The text becomes part of a code-block.
  4. Click on the code icon to try to disable the code block, notice that the text is shifted to the left by two spaces.
  5. Keep clicking the code block icon, notice that the previous spacing keeps getting deleted.

Expected behavior Even after starting with 4 spaces, the typed text should still be text, not a code block.

Version information Browser: Chrome Version 101.0.4951.64 (arm64) EasyMDE version: v2.16.1

Ionaru commented 2 years ago

4 spaces starting a code block is intentional and multiple markdown specifications mention it.

https://spec.commonmark.org/0.30/#tabs https://markdown-guide.readthedocs.io/en/latest/basics.html#code-block

Click on the code icon to try to disable the code block, notice that the text is shifted to the left by two spaces.

It's actually turning the 4 spaces into a tab character, which is also valid for a code block.

Keep clicking the code block icon, notice that the previous spacing keeps getting deleted.

With the text selected, the editor will then surround the text with ` characters, toggling the code block.