yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.92k stars 324 forks source link

Enter at the end of a single-line list item with trailing spaces should add an indented blank line #884

Open af4jm opened 3 years ago

af4jm commented 3 years ago

With an existing ordered list, add 2 spaces to the end of a line and press Enter... what we've done is added a "br" tag to the HTML inside the "ol" tag started on the previous line... however, this extension incorrectly adds the next list prefix (e.g. "2." at the start of the next line, if we added the spaces tot he end of the "1." item

Additionally, if auto-renumber is enabled, succeeding items are incorrectly renumbered when the bogus prefix is added, and the only way to correct those numbers is manually... indenting that line or deleting the bogus prefix does not trigger the list to be renumbered

Example: (cursor is where I have put | and there are exactly 2 spaces before it after the end of the text...

1. test  |
2. test2

If I press Enter, my HTML changes from (again | represents the cursor position):

<ol><li>test|</li><li>test2</li></ol>

to

<ol><li>test<br/>|</li><li>test2</li></ol>

so the correct markdown is

1. test  
|
2. test2

not

1. test  
2. |
3. test2

which renders the following in HTML, with 2 items in the list:

<ol><li>test<br/>2.|</li><li>test2</li></ol>
Lemmingh commented 3 years ago

Excuse me, you first example is parsed as:

<document xmlns="http://commonmark.org/xml/1.0">
  <list type="ordered" start="1" tight="true" delimiter="period">
    <item>
      <paragraph>
        <text>test</text>
      </paragraph>
    </item>
    <item>
      <paragraph>
        <text>test2</text>
      </paragraph>
    </item>
  </list>
</document>

See:

Thus, there is no way to learn your intention, that is, we cannot know that "you're going to make the first list item multiline, or create a loose list".

yzhang-gh commented 3 years ago

I am not sure what you expected. But if I only look at this

so the correct markdown is

1. test  
|
2. test2

not

1. test  
2. |
3. test2

You just need to press Backspace again.

884

af4jm commented 3 years ago

wow, that's bizarre.. the behavior I'm seeing is very different... if I do backspace it takes out indentation but leaves the number there... to specifically answer @Lemmingh the way to see the difference is with the 2 spaces at the end of the line, which instructs the Markdown interpreter to put a "br" tag and keep the next line in the same block object... and I did try turning auto-renumbering back on and see that is working as expected if the number and . are the only things on the line... if there's something after it, it gets wonky as the tabs are backspaced out

https://user-images.githubusercontent.com/849948/105379686-1698a500-5bdb-11eb-9215-d1fc97be47b5.mp4

yzhang-gh commented 3 years ago

if there's something after it, it gets wonky as the tabs are backspaced out

Alright, the thing is

1. one
   1. one
2. |foo
   1. two
  1. one
    1. one
  2. foo
    1. two

So far so good.

If we press Backspace, it becomes

1. one
   1. one
   |foo
   1. two
  1. one
    1. one foo
    2. two

It should have been

1. one
   1. one
   foo
   2. two

This issue has nothing to do with neither the GFM line break option nor the trailing spaces.

It looks really hard to fix as we are now relying on regular expressions to parse the list.

af4jm commented 3 years ago

is it possible to just put in a check that says if the last 2 characters before the line break are both spaces, skip putting anything on the next line? Then the edge case of the wonky renumbering won't even happen.

Sorry, I am a dev, but I have no experience with Lexers, and very little with RegEx, I do mostly web-based .NET

yzhang-gh commented 3 years ago

You can just press Shift+Enter to get a normal line break.

cc @Lemmingh Probably we need to mention this somewhere in the documentation.

irvnriir commented 3 years ago

To clarify, without 2 Spaces at end of previous line, in some programs text on the next line will be added to the previous .

text_1
text_2

\|/

text_1 text_2

GitHub doesn't require these Spaces .

Lemmingh commented 3 years ago

without 2 Spaces at end of previous line, in some programs text on the next line will be added to the previous

Because CommonMark leaves the rendering of soft line break implementation-dependent:

A conforming parser may render a soft line break in HTML either as a line ending or as a space.

irvnriir commented 3 years ago

@Lemmingh The 2 Spaces is supported almost at all times, the case in GitHub Markdown 's syntax doesn't contradict with it .

Lemmingh commented 3 years ago

Are we ... talking about the same thing?

Within some inline structures (textual content, emphasis, etc.) of a paragraph, if you end a line with 2 or more spaces, or a backslash, you are inserting a hard line break. Otherwise, it's a soft line break. CommonMark defines that a hard line break is rendered as a <br>, but lets implementations decide how to render soft line breaks.

irvnriir commented 3 years ago

We are putting junk into this Issue .

if 2 Spaces insert "hard line break" then i never mentioned "soft line break" .

munael commented 3 years ago

You can just press Shift+Enter to get a normal line break.

cc @Lemmingh Probably we need to mention this somewhere in the documentation.

This currently does not maintain indentation. It always pushes you to the "start" of the level, while I'd expect them to align with the text rather than the list starting token.

This currently happens:

1. foo
|

While I'd want this to happen:

1. foo
   |
Lemmingh commented 3 years ago

Shift+Enter (markdown.extension.onShiftEnterKey) was introduced in #210. It's designed to pretend that our product (Markdown All in One) does not exist, to let VS Code behave as if it's on a plain text document with no extension installed.