Wrap entire document with a blockquote

I just can’t seem to figure out how to wrap the entire document as a blockquote…

I have tried the following to show the entire content as selected and tried updating in place:

  const sel = prosemirrorState.TextSelection.between(doc.resolve(0), doc.resolve(doc.content.size))
  view.dispatch(view.state.tr.setSelection(sel))

But it seems like the view will not update.

I have also tried programatically running the commands selectAll and wrapIn to see if I could get those to work as well, but nothing happens.

I’ve also tried using the findWrapping method, but I seem to get a null result there. I have also tried using the wrap method, but it says that it is not valid doc content.

I’ve even tried using replaceWith, but it seems to just replace the state with the existing state, instead of the wrapped state by creating the blockquote node with the state content inside of it…

Here’s another code snippet I’ve tried.

  const sel = prosemirrorState.TextSelection.between(doc.resolve(0), doc.resolve(doc.content.size))
  tr.setSelection(sel)
  tr.replaceSelectionWith(state.schema.nodes.blockquote.create({}, state.doc.content))
  view.dispatch(tr)

Something like that should work.

import { TextSelection } from 'prosemirror-state';
import { findWrapping } from 'prosemirror-transform';

 const selectionFrom = new TextSelection(state.doc.resolve(0));
      const selectionTo = new TextSelection(
        state.doc.resolve(state.doc.content.size),
      );

      const range = selectionFrom.$from.blockRange(selectionTo.$to);
      const wrapping =
        range && findWrapping(range, schema.nodes.blockquote, {});

      dispatch(state.tr.wrap(range, wrapping).scrollIntoView());
1 Like