code: private void filter(Element list)
      {
          // Iterate all the child nodes of the given list to see who's allowed and who's not allowed inside it.
          Node child = list.getFirstChild();
          Node previousListItem = null;
          while (child != null) {
              Node nextSibling = child.getNextSibling();
              if (isAllowedInsideList(child)) {
                  // Save a reference to the previous list item. Note that the previous list item is not necessarily the
                  // previous sibling.
                  if (child.getNodeName().equalsIgnoreCase(TAG_LI)) {
                      previousListItem = child;
                  }
              } else {
                  if (previousListItem == null) {
                      // Create a new list item to be able to move the invalid child.
                      previousListItem = list.getOwnerDocument().createElement(TAG_LI);
                      list.insertBefore(previousListItem, child);
                      // Hide the marker of the list item to make the list look the same after it is cleaned.
                      ((Element) previousListItem).setAttribute(ATTRIBUTE_STYLE, "list-style-type: none");
                  }
                  // Move the child node at the end of the previous list item because it is not allowed where it is now.
                  previousListItem.appendChild(child);
              }
              child = nextSibling;
          }
      }
docs: Transforms the given list in a valid XHTML list by moving the nodes that are not allowed inside &lt;ul&gt; and
  &lt;ol&gt; in &lt;li&gt; elements.
  
  @param list the list to be filtered