code: private void surroundWithParagraph(Document document, Node body, Node beginNode, Node endNode)
      {
          // surround all the nodes starting with the marker node with a paragraph.
          Element paragraph = document.createElement(TAG_P);
          body.insertBefore(paragraph, beginNode);
          Node child = beginNode;
          while (child != endNode) {
              Node nextChild = child.getNextSibling();
              paragraph.appendChild(body.removeChild(child));
              child = nextChild;
          }
      }
docs: Surround passed nodes with a paragraph element.
  
  @param document the document to use to create the new paragraph element
  @param body the body under which to wrap non valid elements with paragraphs
  @param beginNode the first node where to start the wrapping
  @param endNode the last node where to stop the wrapping. If null then the wrapping is done till the last element
  inside the body element