# Replace Image With Text On Text Copy

**URL:** https://discuss.prosemirror.net/t/replace-image-with-text-on-text-copy/3518
**Category:** Uncategorized
**Created:** [February 20, 2021, 4:13am UTC](https://discuss.prosemirror.net/t/replace-image-with-text-on-text-copy/3518 "2021-02-20T04:13:09Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![jorisgu](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jorisgu/32/2313_2.png) [@jorisgu](https://discuss.prosemirror.net/u/jorisgu)
#### Post date: [August 30, 2021, 5:28pm UTC](https://discuss.prosemirror.net/t/replace-image-with-text-on-text-copy/3518/7 "2021-08-30T17:28:26Z")

</div>

Hi there, I implemented my own textBetween method and provide it as a clipboardTextSerialize myself: It checks the presence of a `value` attribute when a node is a `leaf` node and use this value as a text.

```auto
import {
  Node as ProseMirrorNode,
  DOMOutputSpec,
  NodeSpec,
  DOMSerializer,
  Slice,
  Fragment,
} from 'prosemirror-model';

  function customTextBetween(
    fragment: Fragment,
    from: number,
    to: number,
    blockSeparator: string,
    leafText?: string
  ) {
    let text = '',
      separated = true;
    fragment.nodesBetween(
      from,
      to,
      (node, pos) => {
        if (node.isText) {
          text += node.text?.slice(Math.max(from, pos) - pos, to - pos);
          separated = !blockSeparator;
        } else if (node.isLeaf && node.attrs.value != undefined) {
          console.log('LEAF NODE WITH VALUE:', node);
          text += ' '+node.attrs.value+' ';
          separated = !blockSeparator;
        } else if (node.isLeaf && leafText) {
          console.log('ORIGINAL LEAF NODE BEHAVIOUR:', node);
          text += leafText;
          separated = !blockSeparator;
        } else if (!separated && node.isBlock) {
          text += blockSeparator;
          separated = true;
        }
      },
      0
    );
    return text;
  }

...
// in the Editor props:

          clipboardTextSerializer: (slice: Slice) => {
            return customTextBetween(
              slice.content,
              0,
              slice.content.size,
              '\n\n',
              '<classic leaf replacement text>'
            );
          },

```

Hope it helps someone! 😉

---

_[View the full topic](https://discuss.prosemirror.net/t/replace-image-with-text-on-text-copy/3518)._
