web-components
web-components copied to clipboard
Blank Lines Cannot Get Copied and Pasted
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
Current Behavior
Possible Solution
Steps to Reproduce
- Write two lines of text and create few blank lines between them.
- Copy that block of text which will also contain the blank lines and paste it down below
- 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
@irmerk @jeromesimeon is this because markdown doesn't preserve white space?
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
@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 I think it was probably because of how the line was being created. I did some tests and now it works fine.
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.
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?
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 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.
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 that sounds like something that needs to come from @accordproject/markdown-transform
?
Agreed. I will move the discussion to this issue: https://github.com/accordproject/markdown-transform/issues/362