Yes, you can use the shared solution to get the desired output. You may add following highlighted code snippet in ExtractContent method to fix this issue.
public static ArrayList ExtractContent(Node startNode, Node endNode, bool isInclusive)
{
// First check that the nodes passed to this method are
valid for use.
VerifyParameterNodes(startNode, endNode);
// Create a list to store the extracted nodes.
ArrayList nodes = new ArrayList();
// Keep a record of the original nodes passed to this
method so we can split marker nodes if needed.
Node
originalStartNode = startNode;
Node
originalEndNode = endNode;
// Extract content based on block level nodes (paragraphs
and tables). Traverse through parent nodes to find them.
// We will split the content of first and last nodes
depending if the marker nodes are inline
while (startNode.ParentNode.NodeType != NodeType.Body)
startNode =
startNode.ParentNode;
while (endNode.ParentNode.NodeType != NodeType.Body)
endNode =
endNode.ParentNode;
bool
isExtracting = true;
bool
isStartingNode = true;
bool
isEndingNode = false;
// The current node we are extracting from the document.
Node
currNode = startNode;
if (currNode.NodeType
== NodeType.Table)
{
nodes.Add(currNode);
currNode =
currNode.NextSibling;
}
// Begin extracting content. Process all block level
nodes and specifically split the first and last nodes when needed so paragraph
formatting is retained.
// Method is little more complex than a regular extractor
as we need to factor in extracting using inline nodes, fields, bookmarks etc as
to make it really useful.
while (isExtracting)
{