Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve whitespace between Slate and CiceroMark #362

Open
dselman opened this issue Mar 2, 2021 · 3 comments
Open

Preserve whitespace between Slate and CiceroMark #362

dselman opened this issue Mar 2, 2021 · 3 comments

Comments

@dselman
Copy link
Sponsor Contributor

dselman commented Mar 2, 2021

Feature Request πŸ›οΈ

When the user is editing using the Slate editor they are free to insert blank paragraphs to add additional whitespace to their documents. This whitespace is currently lost when the Slate DOM is converted to CiceroMark (which happens when you copy/paste the contents to convert it to HTML.)

Use Case

Allows users to have whitespace within their documents.

Possible Solution

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

return removeEmptyParagraphs(result);

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).

Context

Detailed Description

@dselman
Copy link
Sponsor Contributor Author

dselman commented Mar 2, 2021

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.

@jeromesimeon
Copy link
Member

There is no way to preserve whitespace in markdown.

@jolanglinais
Copy link
Member

I'm inclined to think this should be a Resolution: Wontfix πŸ™…β€β™€οΈ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants