Structure Text editor does not copy/paste styles anymore

For about 1 week now, when copying and pasting into the structured text editor, styles are no longer copied, and all text is copied as BOLD.

See the video:

@primoz.rome Could you please share that Google Doc with me (r.tuan@datocms.com, view-only is fine) so I can take a look at its formatting?

I tried to replicate it on a simpler document and it seems to work OK:

So maybe there is some edge case (some special formatting character, maybe…?) in the original GDoc that we’re not parsing correctly.

Does it happen to you even with a new blank GDoc (https://docs.new) ?

@roger

It happens with any GDoc, even if I go and create a blank one with a simple paragrah (tried that just now). We didnt have this problem with any of our Google Docs but started to see this behaviour about a week ago.

@primoz.rome Does it happen in a Chrome incognito window (with no browser extensions), or in another browser like Firefox or Safari?

And which macOS version is this, by the way?

Sorry @primoz.rome, nevermind, I got it to happen in Chrome as well. I didn’t realize I was using Firefox earlier, sorry. I’ll report it for you right away.

As a temporary workaround, if you first paste it into an intermediary HTML field (either in DatoCMS or in a generic rich text editor like https://www.tiny.cloud/docs/tinymce/latest/basic-example/), and then copy THAT and paste it into structured text, it should work OK again.

I think this is a bug on our side related to how we parse the HTML generated by Google Docs in particular. I’ve reported it and will let you now as soon as it’s fixed. Sorry about that!

Side note: I just wanted to share an interesting aside from the investigation so far. This is one of the stranger bugs I’ve seen… and in this case, it actually looks to be a GDocs issue — one that we’ve had a workaround for for many years, but apparently that workaround regressed and isn’t currently working. We’ll fix it ASAP.

But I had no idea just how pervasive this underlying bug was… apparently it’s been around forever, and it’s because Google Docs’s copied HTML has a <b></b> tag that wraps everything… but only when copied in Chrome and Safari:

<b style="font-weight:normal;" id="docs-internal-guid-4a573200-7fff-848b-1bde-d320d4e94ac8"><p
        dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">This is a </span><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">test</span><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;"> of </span><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">rich</span><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;"> </span><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:700;font-style:italic;font-variant:normal;text-decoration:underline;-webkit-text-decoration-skip:none;text-decoration-skip-ink:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">text</span><span
        style="font-size:11pt;font-family:Arial,sans-serif;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">.</span>
</p></b>

They’re using it to hold an internal GUID. But this causes all sorts of headaches for everyone downstream, e.g.

I don’t know why Google Docs does this. But apparently Firefox stealth-fixes it on copy in a way Chrome and Safari do not (maybe it’s a GDocs + Webkit/Blink bug that doesn’t affect Gecko?).

We’ve even had our own preprocessor specifically for this Google Docs bug: https://github.com/datocms/structured-text/blob/main/packages/html-to-structured-text/src/preprocessors/google-docs.ts but it must’ve stopped working recently. We’ll fix it as soon as we can!

Just thought I’d share because it’s interesting how many people this one GDocs issue has affected over the years, at companies big and small…

2 Likes

We have a hopeful patch for this awaiting code review. I’ll let you know if it either passes and gets deployed or needs further fixes.

@primoz.rome This should be fixed now! Sorry about the delay. It was a complex situation that took some digging to figure out.

Should work now! Please let me know if you still see anything strange.

Awesome, thank a lot for providing such a quick solution :clap: