accordproject / markdown-editor

Markdown editor based on Slate.js
Apache License 2.0
42 stars 47 forks source link

PASTE: handle single paragraphs [WAS: handle links] #209

Closed dselman closed 4 years ago

dselman commented 4 years ago

Input (https://www.bbc.co.uk/news/business-50723392):

In November SoftBank's chief executive, Masayoshi Son, admitted that his judgement had been poor in relation to the investment in the office space start-up.

Error:

[Error] TypeError: firstChild.hasBlockChildren is not a function. (In 'firstChild.hasBlockChildren()', 'firstChild.hasBlockChildren' is undefined) rethrowCaughtError (react-dom.development.js:6284) runEventsInBatch (react-dom.development.js:748) runExtractedPluginEventsInBatch (react-dom.development.js:880) handleTopLevel (react-dom.development.js:5807) batchedEventUpdates$1 (react-dom.development.js:24368) batchedEventUpdates (react-dom.development.js:1419) dispatchEventForPluginEventSystem (react-dom.development.js:5898) attemptToDispatchEvent (react-dom.development.js:6014) dispatchEvent (react-dom.development.js:5918) dispatchEvent unstable_runWithPriority (scheduler.development.js:818) discreteUpdates$1 (react-dom.development.js:24384) discreteUpdates (react-dom.development.js:1442) dispatchDiscreteEvent (react-dom.development.js:5885) dispatchDiscreteEvent

jeromesimeon commented 4 years ago

This one seems to be more about the onPaste/Slate DOM internally than about the markdown transform. I see a proper CiceroMark (AFAICT) inside the onPate:

ONPASTE HTML: <meta charset='utf-8'><br
class="Apple-interchange-newline"><span style="color: rgb(64, 64, 64);
font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
font-size: 16px; font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing: normal;
orphans: 2; text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);
text-decoration-style: initial; text-decoration-color: initial;
display: inline !important; float: none;">In
November<span> </span></span><a
href="https://www.bbc.co.uk/news/business-50312345"
class="story-body__link" style="border-width: 0px 0px 1px;
border-top-style: initial; border-right-style: initial;
border-bottom-style: solid; border-left-style: initial;
border-top-color: initial; border-right-color: initial;
border-bottom-color: rgb(220, 220, 220); border-left-color: initial;
border-image: initial; color: rgb(34, 34, 34); font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-variant-numeric: inherit; font-variant-east-asian: inherit;
font-stretch: inherit; font-family: Helmet, Freesans, Helvetica,
Arial, sans-serif; font-size: 16px; font-weight: bold; letter-spacing:
normal; line-height: 1.375; margin: 0px; padding: 0px; vertical-align:
baseline; text-decoration: none; -webkit-tap-highlight-color: rgba(17,
103, 168, 0.3); orphans: 2; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2; word-spacing:
0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
255);">SoftBank's chief executive, Masayoshi Son, admitted that his
judgement had been poor</a><span style="color: rgb(64, 64, 64);
font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
font-size: 16px; font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing: normal;
orphans: 2; text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);
text-decoration-style: initial; text-decoration-color: initial;
display: inline !important; float: none;"><span> </span>in relation to
the investment in the office space start-up.</span>

index.js:499 ONPASTE CICM:
{
  "$class": "org.accordproject.commonmark.Document",
  "nodes": [
    {
      "$class": "org.accordproject.commonmark.Text",
      "text": "In\nNovember"
    },
    {
      "$class": "org.accordproject.commonmark.Text",
      "text": " "
    },
    {
      "$class": "org.accordproject.commonmark.Link",
      "nodes": [
        {
          "$class": "org.accordproject.commonmark.Text",
          "text": "SoftBank's\nchief executive, Masayoshi Son, admitted that his judgement had been\npoor"
        }
      ],
      "destination": "https://www.bbc.co.uk/news/business-50312345",
      "title": ""
    },
    {
      "$class": "org.accordproject.commonmark.Text",
      "text": " "
    },
    {
      "$class": "org.accordproject.commonmark.Text",
      "text": "in\nrelation to the investment in the office space\nstart-up."
    }
  ],
  "xmlns": "http://commonmark.org/xml/1.0"
}

index.js:504 ONPASTE SLAT:
{
  "object": "document",
  "data": null,
  "nodes": [
    {
      "object": "text",
      "text": "In\nNovember",
      "marks": []
    },
    {
      "object": "text",
      "text": " ",
      "marks": []
    },
    {
      "object": "inline",
      "type": "link",
      "data": {
        "href": "https://www.bbc.co.uk/news/business-50312345",
        "title": ""
      },
      "nodes": [
        {
          "object": "text",
          "text": "SoftBank's\nchief executive, Masayoshi Son, admitted that his judgement had been\npoor",
          "marks": []
        }
      ]
    },
    {
      "object": "text",
      "text": " ",
      "marks": []
    },
    {
      "object": "text",
      "text": "in\nrelation to the investment in the office space\nstart-up.",
      "marks": []
    }
  ]
}
jeromesimeon commented 4 years ago

More info on this. This failure occurs when trying to Copy/Paste a single paragraph but it works if you cut and paste two paragraphs.

Screenshot 2019-12-11 at 12 16 25 PM
jeromesimeon commented 4 years ago

This specific error occurs when pasting single paragraphs, rather than blocks of them.

From the same BBC article, just using another paragraph without link does the trick.

The error seems to be coming from a text node in the Slate DOM without a paragraph block around it.

Here is a sample trace from within the onPaste calls:

ONPASTE HTML: <meta charset='utf-8'><span style="color: rgb(64, 64,
64); font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
font-size: 16px; font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing: normal;
orphans: 2; text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);
text-decoration-style: initial; text-decoration-color: initial;
display: inline !important; float: none;">The memo also indicated that
Wag has laid off staff as a result of the decision, saying: "Today, we
said goodbye to a number of our friends and colleagues as we align our
organization with the needs of our business."</span>

index.js:499 ONPASTE CICM:
{
  "$class": "org.accordproject.commonmark.Document",
  "nodes": [
    {
      "$class": "org.accordproject.commonmark.Text",
      "text": "The\nmemo also indicated that Wag has laid off staff as a result of the\ndecision, saying: \"Today, we said goodbye to a number of our friends\nand colleagues as we align our organization with the needs of our\nbusiness.\""
    }
  ],
  "xmlns": "http://commonmark.org/xml/1.0"
}

index.js:504 ONPASTE SLAT:
{
  "object": "document",
  "data": null,
  "nodes": [
    {
      "object": "text",
      "text": "The\nmemo also indicated that Wag has laid off staff as a result of the\ndecision, saying: \"Today, we said goodbye to a number of our friends\nand colleagues as we align our organization with the needs of our\nbusiness.\"",
      "marks": []
    }
  ]
}

@DianaLease @dselman Should this be considered a markdown-editor bug (i.e., it should handle a text node without an enclosing paragraph block) or a markdown-transform (i.e., it should not return a text node without an enclosing paragraph block)?

jolanglinais commented 4 years ago

This seems to be resolved.