Пример #1
0
        private void EnsureNewLineAtDocEnd(MarkupPointer mpStart, MarkupPointer mpEnd)
        {
            // Add a <p></p> at the end of the document if there isn't one.
            MarkupPointer endBody = MarkupServices.CreateMarkupPointer();
            endBody.MoveAdjacentToElement(PostBodyElement, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd);

            // If we have to insert the <p> this is where we will do it, so save it for later
            MarkupPointer insertLocation = endBody.Clone();

            // Move left one more time to find out if it is p with a space in it.
            endBody.Left(true);

            // Check to see if it a p with a space.  We use innerHtml because if the html looked like
            // <p><img ...>&nbsp;</p> innerText only reports " " though this isnt really just a blank line.
            // We dont use HtmlUtils.HtmlToText because it will replace img tags as a space.
            if (endBody.CurrentScope.tagName != "P" || endBody.CurrentScope.innerHTML != "&nbsp;")
            {
                // Move it into the real document
                IHTMLDocument2 docInsert = mpStart.GetDocument();
                MarkupRange stagingRangeInsert = MarkupServices.CreateMarkupRange(mpStart, mpEnd);
                stagingRangeInsert.MoveToElement(docInsert.body, false);
                MarkupServices.Move(stagingRangeInsert.Start, stagingRangeInsert.End, insertLocation);
            }
        }