Hi,
I’m using the function GetHTMLFromBookmark, which you so kindly provided me(code below), to pull the contents of a bookmark in HTML form. I then allow the users to edit the HTML & a - enter this info back into the document, b - display the info on a webpage.
private static string GetHtmlFromBookmark(string bookmarkName, Document doc, SaveFormat ThisSaveFormat)
{
Document docClone = doc.Clone();
Document doc1 = new Document();
Bookmark mark = docClone.Range.Bookmarks[bookmarkName];
Node node = mark.BookmarkStart.ParentNode;
Node endNode = mark.BookmarkEnd.ParentNode.NextSibling;
while (!node.Equals(endNode))
{
if ((node as CompositeNode).ChildNodes.Contains(mark.BookmarkStart))
{
Node child = (node as CompositeNode).FirstChild;
Node endChild = mark.BookmarkStart.NextSibling;
while (!child.Equals(endChild))
{
child = child.NextSibling;
child.PreviousSibling.Remove();
}
}
if ((node as CompositeNode).ChildNodes.Contains(mark.BookmarkEnd))
{
Node child = mark.BookmarkEnd;
while (!child.Equals(child.ParentNode.LastChild))
{
child = child.NextSibling;
child.PreviousSibling.Remove();
}
child.Remove();
}
doc1.FirstSection.Body.AppendChild(doc1.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting));
node = node.NextSibling;
if (node == null)
break;
}
MemoryStream stream = new MemoryStream();
doc1.Save(stream, ThisSaveFormat);
string html = Encoding.UTF8.GetString(stream.GetBuffer());
return html;
}
This returns the attached HTML. When displaying a webpage, it messes up the paragraph format. I was wondering how I can display this properly.
Thank you.