public static string Metrofy(ICollection<AwfulPost> posts) { StringBuilder html = new StringBuilder(); html.Append("<table>"); int postCount = posts.Count; foreach (var item in posts) { try { var post = item as AwfulPost; html.Append("<tr><td>"); html.AppendFormat("<a href='#post_{0}' id='postlink{0}' style='display:none'>This should be hidden.</a>", post.PostIndex); html.AppendFormat("<div class='post_header' id='post_{0}' onclick=\"javascript:openPostMenu('{0}')\">", post.PostIndex); if (post.ShowPostIcon) { Uri iconUri = new Uri(post.PostIconUri, UriKind.RelativeOrAbsolute); html.AppendFormat("<img class='post_icon' alt='' src='{0}' />", iconUri.AbsoluteUri); html.AppendFormat("<div class='post_header_text' >", post.PostIndex); html.Append(AppendPostAuthor(post)); html.AppendFormat("<span class='text_subtlestyle'>#{0}/{1}, {2}</span>", post.PostIndex, postCount, post.PostDate); } else { html.Append("<div class='post_header_text_noicon'>"); html.Append(AppendPostAuthor(post)); html.AppendFormat("<span class='text_subtlestyle'>#{0}/{1}, {2}</span>", post.PostIndex, postCount, post.PostDate.ToString("MM/dd/yyyy, h:mm tt")); } var node = new HtmlNode(HtmlNodeType.Element, post.ContentNode.OwnerDocument, -1) { InnerHtml = post.ContentNode.InnerHtml, Name = post.ContentNode.Name }; var content = new MainWebParser(node.FirstChild).Body; html.AppendFormat("</div></div><div class='{0}'><pre>{1}</pre></div></pre></td></tr>", post.HasSeen ? "post_content_seen" : "post_content", content); } catch (Exception ex) { string error = string.Format("There was an error while merging posts. [{0}] {1}", ex.Message, ex.StackTrace); } } html.Append("</table>"); html.Append("</body>"); string result = html.ToString(); return result; }
public override string HandleNode(HtmlNode node) { var innerNode = new MainWebParser(node.FirstChild).Body; node.InnerHtml = innerNode; return node.OuterHtml; }
public override string HandleQuotes(HtmlNode node) { if (node.GetAttributeValue("class", "").Equals("bbc-block")) { var quoteNode = node.Descendants("blockquote").First(); var authorNode = node.Descendants("h4").FirstOrDefault(); string author = null; if (authorNode != null) { author = authorNode.InnerText.Replace(" posted:", ""); } var parser = new QuoteWebParser(author, quoteNode.FirstChild); return parser.Body; } else { var body = new MainWebParser(node.FirstChild).Body; return string.Format("<br/><blockquote>{0}</blockquote><br/>", body); } //return string.Empty; }
public override string HandleLinks(HtmlNode node) { string url = node.Attributes["href"].Value; node.Attributes["href"].Value = String.Format("javascript:navigate('a{0}{1}')", Constants.DEMARC, url); var textNode = node.FirstChild as HtmlTextNode; if (textNode != null) { //if (textNode.Text.Length > 25) //textNode.Text = String.Format("{0}­", node.InnerText); } else { MainWebParser main = new MainWebParser(node.FirstChild); node.InnerHtml = main.Body; } return string.Format("{0}", node.OuterHtml); }