Hi Todd,
Thanks for your inquiry.
I think what you meant is can you insert MS Word type comments within content even when a large amount is inserted using the InsertHTML method.
This is possible, please see the code below:
// This will hold the start and end nodes of the inserted HTML<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
NodeRange nodeRange = new NodeRange();
// Set the node changing handler to catch inserted nodes and pass the node range object used to the store
// the nodes are looking for.
doc.NodeChangingCallback = new FindNodeRangeHtml(nodeRange);
// Insert HTML
builder.InsertHtml("Text to comment");
// Remove the node changing callback
doc.NodeChangingCallback = null;
// Insert a comment around certain text between these two nodes using replace.
doc.Range.Replace(new Regex("Text to comment"), new InsertCommentsReplaceHandler(nodeRange), false);
///
/// Finds the first and last node inserted during the duration of the callback and passes this to the NodeRange object.
///
public class FindNodeRangeHtml : INodeChangingCallback
{
NodeRange mNodeRange;
bool isFirstNode = true;
public FindNodeRangeHtml(NodeRange nodeRange)
{
mNodeRange = nodeRange;
}
void INodeChangingCallback.NodeInserted(NodeChangingArgs args)
{
Document doc = (Document)args.Node.Document;
if (isFirstNode)
{
mNodeRange.StartNode = args.Node;
isFirstNode = false;
}
mNodeRange.EndNode = args.Node;
}
void INodeChangingCallback.NodeInserting(NodeChangingArgs args)
{
}
void INodeChangingCallback.NodeRemoved(NodeChangingArgs args)
{
}
void INodeChangingCallback.NodeRemoving(NodeChangingArgs args)
{
}
}
public class NodeRange
{
private Node mStartNode;
private Node mEndNode;
public Node StartNode
{
get
{
return mStartNode;
}
set
{
mStartNode = value;
}
}
public Node EndNode
{
get
{
return mEndNode;
}
set
{
mEndNode = value;
}
}
}
As you can see it will gather the start and end nodes of the content insterted using the InsertHTML method and stores them in an NodeRange object.
You can then apply comments to specific text using an ReplaceEvaluator. I suggest using the code from Find and Highlight Text sample here as the basis for your comment insertion logic. For instance you split the runs around the text that matches in the same way but instead of highlighting the text you use your code above to insert a comment at the matching text instead. The NodeRange object passed to the handler is used to verify that the match node is occurs within the start and end node.
Thanks,