outline / rich-markdown-editor

The open source React and Prosemirror based markdown editor that powers Outline. Want to try it out? Create an account:
https://www.getoutline.com
BSD 3-Clause "New" or "Revised" License
2.87k stars 588 forks source link

Get `\` instead of empty value when deleting all the content #532

Open sklinov opened 3 years ago

sklinov commented 3 years ago

A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/rich-markdown-editor-slash-oim2w?file=/src/App.tsx
  2. Try to delete all the content or enter \
  3. Check out console or value area to see that on empty value \ is set as a value

Expected behavior Empty string is expected

Version 11.12.0-0

Screenshots

image

Desktop (please complete the following information):

plitzenberger commented 3 years ago

same here. Getting \ for every empty block

gzuidhof commented 2 years ago

I am seeing the same behavior, I haven't been able to figure out the cause.

tommoor commented 2 years ago

This is expected behavior at this time - a single slash is used to encode an empty paragraph, something that markdown doesn’t natively support.

For display you can strip these with a regex

On Thu, Sep 30, 2021 at 13:51 Guido Zuidhof @.***> wrote:

I am seeing the same behavior, I haven't been able to figure out the cause.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/outline/rich-markdown-editor/issues/532#issuecomment-931537247, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC474UPAQGTN4BSIWIENH3UESPTBANCNFSM5CWOSIWQ .

sklinov commented 2 years ago

Yeah, stripping with regexp is that's what I've done eventually, so now my onChange looks like

onChange: (v: () => string) => {
        const val = v();
        const stripRegEx = new RegExp(/^\\\W*$/gm)
        const savedValue = stripRegEx.test(val) ? val.replace(/^\\/, "") : val
        setValue(savedValue);
        save(savedValue);
      },
namlk-hamsa-dev commented 2 years ago

Yeah, stripping with regexp is that's what I've done eventually, so now my onChange looks like

onChange: (v: () => string) => {
        const val = v();
        const stripRegEx = new RegExp(/^\\\W*$/gm)
        const savedValue = stripRegEx.test(val) ? val.replace(/^\\/, "") : val
        setValue(savedValue);
        save(savedValue);
      },

image I do the same as you but get this error. Can anyone help me get rid of that nasty backlash from the end of my string. Thanks