//0 or negative number to have no limit private DataElement GenerateBlogCard(BlogPost p, int lineLimit = -1) { DataElement ret = new DataElement("blogPostCard.html"); Regex isImage = new Regex(@"^[a-z0-9\$\-_\.\+\!\*\'\(\)\,\\\/:]*\.(png|jpg|jpeg|gif)$", RegexOptions.IgnoreCase); Regex isElement = new Regex(@"^[ \t]*<.*", RegexOptions.IgnoreCase); ret.AppendToProperty("#TITLE#", p.Title); ret.AppendToProperty("#DATE#", p.Date.ToLongDateString()); int curLines = 0; foreach (string s in p.Content) { if (s != null && s != "") { if (isImage.IsMatch(s)) { ret.AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<img src=\"{0}\" class=\"img-fluid\" alt=\"{1}\">\n", s, s))); } else if (isElement.IsMatch(s)) { ret.AppendToProperty("#CONTENT#", new LiteralElement(s)); } else { ret.AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<p>{0}</p>\n", s))); } curLines++; } if (lineLimit > 0 && curLines >= lineLimit) { ret.AppendToProperty("#CONTENT#", new LiteralElement(String.Format("<a href=\"{0}\"><font color=#FFFFFF>Continue reading</font></a>", "#URL#"))); break; } } return(ret); }