예제 #1
0
        public string GetEditedHtml(bool preferWellFormed)
        {
            Debug.Assert(undoDepth == 0, "This call should not be surrounded by an undo as is.  The temporary fixup will cause all changes in the current undo stack to rollback!");

            // tell editor to ignore next notify for purposes of dirty tracking
            // (the next notify will be the undo of the temporary fixups and
            // this shouldn't count)
            string html = GetEditedHtmlCore(preferWellFormed);

            TemporaryFixupArgs args = new TemporaryFixupArgs(html);
            if (PerformTemporaryFixupsToEditedHtml != null)
                PerformTemporaryFixupsToEditedHtml(args);

            return args.Html;
        }
        private static void DetachExtendedEntryBehavior(TemporaryFixupArgs args)
        {
            string html = args.Html;

            if (html.Contains(EXTENDED_ENTRY_ID))
            {
                //replace the EXTENDED_ENTRY_ID behavior div with the <!--more--> comment
                StringBuilder output = new StringBuilder(html.Length);
                SimpleHtmlParser parser = new SimpleHtmlParser(html);
                SmartPredicate splitDiv = new SmartPredicate(String.Format(CultureInfo.InvariantCulture, "<div id='{0}'>", EXTENDED_ENTRY_ID));
                for (Element el; null != (el = parser.Next());)
                {
                    if (splitDiv.IsMatch(el))
                    {
                        Element e = parser.Peek(0);
                        if (e is EndTag && ((EndTag)e).NameEquals("div"))
                        {
                            output.Append(BlogPost.ExtendedEntryBreak);
                            parser.Next();
                        }

                    }
                    else
                        output.Append(html, el.Offset, el.Length);
                }
                args.Html = output.ToString();
            }
        }
        private static void EditorContext_PerformTemporaryFixupsToEditedHtml(TemporaryFixupArgs args)
        {
            string html = args.Html;
            if (html.Contains("table"))
            {
                StringBuilder output = new StringBuilder(html.Length);
                SimpleHtmlParser parser = new SimpleHtmlParser(html);
                for (Element el; null != (el = parser.Next());)
                {
                    output.Append(html, el.Offset, el.Length);
                    if (el is BeginTag &&
                        ((BeginTag)el).NameEquals("td"))
                    {
                        Element e = parser.Peek(0);
                        if (e is EndTag && ((EndTag)e).NameEquals("td"))
                            output.Append("&nbsp;");
                    }

                }
                args.Html = output.ToString();
            }
        }