Copy/past formated text from Word or Google Docs into raw text

Hi !

I’m dealing with client that are quite old, not too digital-friendly but that really want to do all text filling on their website. Problem is that they copy paste texts from a large range of text editors like Word or Google Docs that are written and formatted by different authors.

But that styles really override the graphic identity of the website by doing text background color, linethrought and more !

So I really want to force copy-paste to be the simplest it can be for them. Do you think it’s possible ?

Is that in Kirby?

I mean in the Kirby panel you either paste text into a textarea (which strips all formatting) or into a “writer” field, which in theory also removes most formatting (keeps only stuff like bold, italic, links, etc).

Yes sorry I did not precise it, they copy paste textes in a bloc field actually, and it do something like that for example:

And it also change the typeface !

That is unexpected.

Could you share the blueprint of that blocks field?

The blueprint is written like that:

infos:
  label: Contenu gauche
  type: blocks
  fieldsets:
    - heading
    entete:
      name: Entête
      icon: text-center
      fields:
      text:
        label: texte
        type: textarea
    - text
    - image
    - gallery
    - video
    - quote
    - list

I just saw in the page that the block I screened is a custom entete block.

Is there an error in the indenting? text should be inside of fields:

infos:
  label: Contenu gauche
  type: blocks
  fieldsets:
    - heading
    entete:
      name: Entête
      icon: text-center
      fields:
        text: # change here
          label: texte
          type: textarea
    - text
    - image
    - gallery
    - video
    - quote
    - list

I imagine you have a custom preview component for the entete block? I mean the “textarea” field that’s inside of it doesn’t support formatting.

Sorry, it’s a bad copy paste I did, the actual indenting is already as you wrote.

Ok so it’s because I did a textarea ? I only have a block snippet that is :

<p class="entete">
  <?= $block->text()->kt()->inline() ?>
</p>

And nothing more…

I actually think it’s because of the entete preview component: I mean if you would copy paste straight into a textarea from Word, all formatting would be (correctly) removed.
So there must be something in your setup which transforms the “rich text” from your clipboard into HTML, it probably isn’t Kirby so all that is left is the block preview component.

You probably have a plugin somewhere that registers the entete block for the panel:

panel.plugin('some/thing', {
  blocks: {
    entete: {
      template: `<div>in here something probably says "contenteditable"</div>`,
      // more stuff
    }
  }
});

I believe this component is somehow responsible for putting HTML into your textarea, when you don’t want HTML, but rather “Kirbytext”.

You could probably work around this by changing the preview component to simply show a textarea, but there actually is a handy plugin which already does that.

You might want to install that, and then use it as the preview for your custom block:

infos:
  label: Contenu gauche
  type: blocks
  fieldsets:
    - heading
    entete:
      name: Entête
      icon: text-center
      preview: fields # required
      wysiwyg: true # recommended
      fields:
        text:
          label: texte
          type: textarea
    - text
    - image
    - gallery
    - video
    - quote
    - list
1 Like

Yes, actually the index.js of my plugin is:

panel.plugin( "fromager-f/entete-block", {
  blocks: {
    entete: `
      <div
        contentEditable="true"
        v-html="content.text"
        @input="update({ text: $event.target.innerHTML })"
        name="entete"></div>
    `
  }
});

That is perfect !
With the plugin the copy/paste is totally unformated, thanks !

Perfect, at this point you can also delete the index.js file from your plugin (the one with the entete block), since you no longer use it :slight_smile:

1 Like