web-components icon indicating copy to clipboard operation
web-components copied to clipboard

Blank Lines Cannot Get Copied and Pasted

Open d-e-v-esh opened this issue 3 years ago • 11 comments

Bug Report 🐛

When we copy a block of text from one place to another, the text is copied properly but the blank lines between them are not getting copied. This makes formatting more annoying.

Expected Behavior

Osf0jOE0xw

Current Behavior

AkPqpXwcp8

Possible Solution

Steps to Reproduce

  1. Write two lines of text and create few blank lines between them.
  2. Copy that block of text which will also contain the blank lines and paste it down below
  3. You will see that the pasted text will not have blank lines between them.

Context (Environment)

Desktop

  • OS: Windows 10
  • Browser: Chrome
  • Version 88.0.4324.182 (Official Build) (64-bit)

Detailed Description

Possible Implementation

d-e-v-esh avatar Feb 26 '21 16:02 d-e-v-esh

@irmerk @jeromesimeon is this because markdown doesn't preserve white space?

Michael-Grover avatar Feb 26 '21 17:02 Michael-Grover

It's my understanding that if a user were able to save this document and reopen it, any white space like line breaks would be removed when the document is reopened

Michael-Grover avatar Feb 26 '21 17:02 Michael-Grover

@irmerk @jeromesimeon is this because markdown doesn't preserve white space?

I am not sure. This could be an artefact of markdown (there is no way to create random space between paragraphs), or a bug in copy paste. This might need investigation.

jeromesimeon avatar Feb 26 '21 17:02 jeromesimeon

@jeromesimeon I think it was probably because of how the line was being created. I did some tests and now it works fine.

d-e-v-esh avatar Feb 26 '21 17:02 d-e-v-esh

We'll need to do a thorough investigation on all of this to see what is going on, the limitations, and what these changes do.

jolanglinais avatar Mar 01 '21 17:03 jolanglinais

Copy/paste uses the Slate <--> CiceroMark <--> HTML transformation, so it is likely that markdown insignificant whitespace is getting dropped. Perhaps we can be smarter at representing blank paras when we convert from Slate to CiceroMark?

dselman avatar Mar 01 '21 17:03 dselman

Using this input Slate document:

{
    "document": {
      "object": "document",
      "children": [
        {
          "object": "block",
          "data": {},
          "type": "heading_one",
          "children": [
            {
              "object": "text",
              "text": "Heading"
            }
          ]
        },
        {
          "object": "block",
          "type": "paragraph",
          "children": [
            {
              "object": "text",
              "text": "This is some text."
            }
          ],
          "data": {}
        },
        {
            "object": "block",
            "type": "paragraph",
            "children": [
              {
                "object": "text",
                "text": ""
              }
            ],
            "data": {}
          },
        {
          "object": "block",
          "type": "paragraph",
          "children": [
            {
              "object": "text",
              "text": "This is more text."
            }
          ],
          "data": {}
        }
      ],
      "data": {}
    }
  }  

And running:

markus transform --input slate.json --from slate --to html

The following HTML is produced:

<html>
<body>
<div class="document">
<h1>Heading</h1>
<p>This is some text.</p>
<p>This is more text.</p>
</div>
</body>
</html>

Showing that the Slate paragraph containing an empty text node got removed during the transformation from Slate to ciceromark_parsed.

dselman avatar Mar 01 '21 18:03 dselman

@dselman What should be the proper solution to this? I didn't pay much attention to this problem and kind of tinkered here and there with few things until it worked.

d-e-v-esh avatar Mar 01 '21 18:03 d-e-v-esh

This line removes empty paragraphs when converting from Slate to CiceroMark:

https://github.com/accordproject/markdown-transform/blob/f68f7a33dece4d106c6a17a698b1f411441ef0d9/packages/markdown-slate/lib/slateToCiceroMarkDom.js#L86

While this handles the conversion from CiceroMark to Slate:

https://github.com/accordproject/markdown-transform/blob/master/packages/markdown-slate/lib/ToSlateVisitor.js#L532

CiceroMark whitespace handling should be consistent with markdown (i.e. whitespace is not significant), however you can force a hard line break in markdown using \ (see output from https://spec.commonmark.org/dingus/ using the markdown below)

## Try CommonMark

This is 1

This is 2.
\
\
\
\
This is 3

So, one approach would be to replace empty paragraphs in the Slate DOM with hard line breaks in the CiceroMark DOM (and vice-a-versa, to preserve roundtripping).

dselman avatar Mar 01 '21 19:03 dselman

@dselman that sounds like something that needs to come from @accordproject/markdown-transform?

jolanglinais avatar Mar 02 '21 15:03 jolanglinais

Agreed. I will move the discussion to this issue: https://github.com/accordproject/markdown-transform/issues/362

dselman avatar Mar 02 '21 16:03 dselman