public override void VisitEmbedTag(EmbedTag tag) { if (!Truncating) { writer.EmbedExisting(tag.AttachmentName); } }
public void VisitEmbedTag(EmbedTag tag) { AttachmentData attachment = testStepRun.TestLog.GetAttachment(tag.AttachmentName); if (attachment == null) { return; } string src = formatter.GetAttachmentFileInfo(testStepRun.Step.Id, attachment).FullName; writer.Write("<div class=\"logStreamEmbed\">"); if (attachment.ContentType.StartsWith("image/")) { writer.Write("<a href=\""); writer.Write(src); writer.Write("\" class=\"attachmentLink\">"); writer.Write("<img class=\"embeddedImage\" src=\""); WriteHtmlEncoded(writer, src); writer.Write("\" alt=\"Attachment: "); WriteHtmlEncoded(writer, attachment.Name); writer.Write("\" /></a>"); } else if ((attachment.ContentType.StartsWith("text/html") || attachment.ContentType.StartsWith("text/xhtml")) && attachment.IsText) { writer.Write(attachment.GetText()); } else if (attachment.ContentType.StartsWith("text/") && attachment.IsText) { writer.Write("<pre>"); WriteHtmlEncodedWithBreaks(writer, attachment.GetText()); writer.Write("</pre>"); } else if (flashEnabled && attachment.ContentType.StartsWith(MimeTypes.FlashVideo)) { string placeholderId = "video-" + Hash64.CreateUniqueHash(); writer.Write("<div id=\""); writer.Write(placeholderId); writer.Write("\">"); writer.Write("<script type=\"text/javascript\">"); writer.Write("swfobject.embedSWF('"); WriteHtmlEncoded(writer, new Uri(Path.Combine(formatter.jsDir, "player.swf")).ToString()); writer.Write("', '"); writer.Write(placeholderId); writer.Write("', '400', '300', '9.0.98', '"); WriteHtmlEncoded(writer, new Uri(Path.Combine(formatter.jsDir, "expressInstall.swf")).ToString()); writer.Write("', {file: '"); WriteHtmlEncoded(writer, new Uri(src).ToString()); writer.Write("'}, {allowfullscreen: 'true', allowscriptaccess: 'always'}, {id: '"); writer.Write(placeholderId); writer.Write("'})"); writer.Write("</script>"); writer.Write("</div>"); } else { writer.Write("Attachment: <a href=\""); WriteHtmlEncoded(writer, src); writer.Write("\" class=\"attachmentLink\">"); WriteHtmlEncoded(writer, attachment.Name); writer.Write("</a>"); } writer.Write("</div>"); }
public void VisitEmbedTag(EmbedTag tag) { }
public static string ConvertToUbb(string htmlContent, ContentConvert beforeConvert, ContentConvert afterConvert) { string msg = string.Empty; htmlContent = htmlContent.Replace("\n", string.Empty); htmlContent = htmlContent.Replace("\r", string.Empty); htmlContent = regScript.Replace(htmlContent, string.Empty); htmlContent = regStyle.Replace(htmlContent, string.Empty); // htmlContent = htmlContent.Trim(); if (beforeConvert != null) { htmlContent = beforeConvert(htmlContent); } MatchCollection matchs = regTag.Matches(htmlContent); int tagIndex = 0; List <HtmlTagBase> tags = new List <HtmlTagBase>() , beginTags = new List <HtmlTagBase>() , endTages = new List <HtmlTagBase>() , singleTags = new List <HtmlTagBase>(); foreach (Match m in matchs) { HtmlTagBase t; string tagName = m.Groups[1].Value; //这里也可以根据HTML标签来反射生成Html标签类, 代码可以少很多, 但是这样性能不好。 switch (tagName.ToLower()) { case "img": t = new ImgTag(tagIndex, m.Value, m.Index); break; case "a": t = new ATag(tagIndex, m.Value, m.Index); break; case "font": t = new FontTag(tagIndex, m.Value, m.Index); break; case "span": t = new SpanTag(tagIndex, m.Value, m.Index); break; case "br": t = new BrTag(tagIndex, m.Value, m.Index); break; case "div": t = new DivTag(tagIndex, m.Value, m.Index); break; case "p": t = new PTag(tagIndex, m.Value, m.Index); break; case "table": t = new TableTag(tagIndex, m.Value, m.Index); break; case "ol": case "ul": t = new ListTag(tagIndex, m.Value, m.Index); break; case "td": case "tr": case "s": case "b": case "i": case "sub": case "sup": case "u": t = new PairTag(tagIndex, m.Value, m.Index); break; case "th": t = new PairTag(tagIndex, m.Value, m.Index); ((PairTag)t).UbbTag = "td"; break; case "strong": t = new PairTag(tagIndex, m.Value, m.Index); ((PairTag)t).UbbTag = "b"; break; case "em": t = new PairTag(tagIndex, m.Value, m.Index); ((PairTag)t).UbbTag = "i"; break; case "strike": t = new PairTag(tagIndex, m.Value, m.Index); ((PairTag)t).UbbTag = "s"; break; case "blockquote": t = new PairTag(tagIndex, m.Value, m.Index); ((PairTag)t).UbbTag = "indent"; break; case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": t = new HTag(tagIndex, m.Value, m.Index); break; case "embed": t = new EmbedTag(tagIndex, m.Value, m.Index); break; default: t = new HtmlTagBase(tagIndex, m.Value, m.Index); break; } tagIndex++; t.TagList = tags; tags.Add(t); if (t.IsSingleTag) { singleTags.Add(t); } else { if (!t.IsEndTag) { beginTags.Add(t); } else { int flag = -1; for (int i = beginTags.Count - 1; i >= 0; i--) { if (beginTags[i].TagName == t.TagName)//匹配开始标记和结束标记 { flag = i; beginTags[i].Pair = t; t.Pair = beginTags[i]; break; } } if (flag >= 0) { for (int i = beginTags.Count - 1; i >= flag; i--) { beginTags.RemoveAt(i); } } } } } StringBuilder builder = new StringBuilder(htmlContent); for (int i = 0; i < tags.Count; i++) { if (!tags[i].IsSingleTag) { if (tags[i].Pair == null) { msg += tags[i].TagName + "没有对应的" + (tags[i].IsEndTag ? "开始" : "结束") + "标记\r\n"; } } if (!tags[i].IsEndTag || tags[i].IsSingleTag) { builder = tags[i].ConvertToUBB(builder); } } //builder.Replace(" ", string.Empty); builder.Replace("\t", string.Empty); htmlContent = builder.ToString(); htmlContent = new Regex("<.*?>").Replace(htmlContent, string.Empty); htmlContent = HttpUtility.HtmlDecode(htmlContent); if (afterConvert != null) { htmlContent = afterConvert(htmlContent); } return(htmlContent); }
/// <inheritdoc /> public virtual void VisitEmbedTag(EmbedTag tag) { RequestMinimumSpacing(1); Append(String.Format("[Attachment: {0}]", tag.AttachmentName)); RequestMinimumSpacing(1); }
public void VisitEmbedTag(EmbedTag tag) { AttachmentData attachment = testStepRun.TestLog.GetAttachment(tag.AttachmentName); if (attachment == null) return; string src = formatter.GetAttachmentFileInfo(testStepRun.Step.Id, attachment).FullName; writer.Write("<div class=\"logStreamEmbed\">"); if (attachment.ContentType.StartsWith("image/")) { writer.Write("<a href=\""); writer.Write(src); writer.Write("\" class=\"attachmentLink\">"); writer.Write("<img class=\"embeddedImage\" src=\""); WriteHtmlEncoded(writer, src); writer.Write("\" alt=\"Attachment: "); WriteHtmlEncoded(writer, attachment.Name); writer.Write("\" /></a>"); } else if ((attachment.ContentType.StartsWith("text/html") || attachment.ContentType.StartsWith("text/xhtml")) && attachment.IsText) { writer.Write(attachment.GetText()); } else if (attachment.ContentType.StartsWith("text/") && attachment.IsText) { writer.Write("<pre>"); WriteHtmlEncodedWithBreaks(writer, attachment.GetText()); writer.Write("</pre>"); } else if (flashEnabled && attachment.ContentType.StartsWith(MimeTypes.FlashVideo)) { string placeholderId = "video-" + Hash64.CreateUniqueHash(); writer.Write("<div id=\""); writer.Write(placeholderId); writer.Write("\">"); writer.Write("<script type=\"text/javascript\">"); writer.Write("swfobject.embedSWF('"); WriteHtmlEncoded(writer, new Uri(Path.Combine(formatter.jsDir, "player.swf")).ToString()); writer.Write("', '"); writer.Write(placeholderId); writer.Write("', '400', '300', '9.0.98', '"); WriteHtmlEncoded(writer, new Uri(Path.Combine(formatter.jsDir, "expressInstall.swf")).ToString()); writer.Write("', {file: '"); WriteHtmlEncoded(writer, new Uri(src).ToString()); writer.Write("'}, {allowfullscreen: 'true', allowscriptaccess: 'always'}, {id: '"); writer.Write(placeholderId); writer.Write("'})"); writer.Write("</script>"); writer.Write("</div>"); } else { writer.Write("Attachment: <a href=\""); WriteHtmlEncoded(writer, src); writer.Write("\" class=\"attachmentLink\">"); WriteHtmlEncoded(writer, attachment.Name); writer.Write("</a>"); } writer.Write("</div>"); }
/// <inheritdoc /> public virtual void VisitEmbedTag(EmbedTag tag) { }