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(); } }
/// <summary> /// Is the tag a meaningless tag such as <p></p> or <a href="..."></a> or <a href="..."> </a> /// </summary> /// <param name="htmlParser"></param> /// <param name="bt"></param> /// <returns></returns> private static bool RemoveMeaninglessTags(SimpleHtmlParser htmlParser, BeginTag bt) { // Look to see if the tag is a <p> without any attributes if ((bt.NameEquals("p") && bt.Attributes.Length == 0 && !bt.HasResidue)) { Element e = htmlParser.Peek(0); // Look to see if thereis a matching end tag to the element we are looking at if (e != null && e is EndTag && ((EndTag)e).NameEquals("p")) { // eat up the end tag htmlParser.Next(); return(true); } } // Look to see if the tag is an <a> without a style/id/name attribute, but has an href... meaning the link is not useful if ((bt.NameEquals("a") && bt.GetAttribute("name") == null && bt.GetAttributeValue("style") == null && bt.GetAttributeValue("id") == null && bt.GetAttributeValue("href") != null)) { bool hadWhiteSpaceText = false; Element e = htmlParser.Peek(0); // Look to see if the a just has whitespace inside of it if (e is Text && HtmlUtils.UnEscapeEntities(e.RawText, HtmlUtils.UnEscapeMode.NonMarkupText).Trim().Length == 0) { e = htmlParser.Peek(1); hadWhiteSpaceText = true; } // Look to see if thereis a matching end tag to the element we are looking at if (e != null && e is EndTag && ((EndTag)e).NameEquals("a")) { // if this was an <a> with whitespace in the middle eat it up if (hadWhiteSpaceText) { htmlParser.Next(); } // eat up the end tag htmlParser.Next(); return(true); } } return(false); }
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(" "); } } } args.Html = output.ToString(); } }