private HtmlImageTag InvokeImageParsedEvent(string url, string altText) { // Markdig TODO // string linkID = altText.ToLowerInvariant(); HtmlImageTag args = new HtmlImageTag(url, url, altText, ""); _imageDelegate(args); return(args); }
public void should_ignore_urls_starting_with_ww_http_and_https(string imageUrl) { // Arrange HtmlImageTag htmlImageTag = new HtmlImageTag(imageUrl, imageUrl, "alt", "title"); // Act HtmlImageTag actualTag = _srcParser.Parse(htmlImageTag); // Assert imageUrl.ShouldBe(actualTag.Src); }
public void absolute_paths_should_be_prefixed_with_attachmentpath(string path, string expectedPath) { // Arrange _urlHelper .Content(Arg.Any <string>()) .Returns(callInfo => callInfo.Arg <string>()); _textSettings.AttachmentsUrlPath = "/attuchments/"; HtmlImageTag htmlImageTag = new HtmlImageTag(path, path, "alt", "title"); // Act HtmlImageTag actualTag = _srcParser.Parse(htmlImageTag); // Assert expectedPath.ShouldBe(actualTag.Src); }
public void WalkAndBindParseEvents(MarkdownObject markdownObject) { foreach (MarkdownObject child in markdownObject.Descendants()) { // LinkInline can be both an <img.. or a <a href="..."> LinkInline linkInline = child as LinkInline; if (linkInline != null) { EnsureAttributesInLink(linkInline); if (linkInline.IsImage) { string altText = ""; var descendentForAltTag = child.Descendants().FirstOrDefault(); if (descendentForAltTag != null) { altText = descendentForAltTag.ToString(); } string title = altText; if (_imageDelegate != null) { HtmlImageTag args = InvokeImageParsedEvent(linkInline.Url, altText); if (!string.IsNullOrEmpty(args.Alt)) { altText = args.Alt; } if (!string.IsNullOrEmpty(args.Title)) { title = args.Title; } // Update the HTML from the data the event gives back linkInline.Url = args.Src; } // Replace to alt= attribute, it's a literal var literalInline = new LiteralInline(altText); linkInline.FirstChild.ReplaceBy(literalInline); // HTML5 the tag linkInline.Title = title; // Necessary for links and Bootstrap 3 AddAttribute(linkInline, "border", "0"); // Make all images expand via this Bootstrap class AddClass(linkInline, "img-responsive"); } else { if (_linkDelegate != null) { string text = linkInline.Title; var descendentForAltTag = child.Descendants().FirstOrDefault(); if (descendentForAltTag != null) { text = descendentForAltTag.ToString(); } HtmlLinkTag args = InvokeLinkParsedEvent(linkInline.Url, text, linkInline.Label); // Update the HTML from the data the event gives back linkInline.Url = args.Href; if (!string.IsNullOrEmpty(args.Target)) { AddAttribute(linkInline, "target", args.Target); } if (!string.IsNullOrEmpty(args.CssClass)) { AddClass(linkInline, args.CssClass); } // Replace the link's text var literalInline = new LiteralInline(args.Text); linkInline.FirstChild.ReplaceBy(literalInline); } // Markdig TODO: make these configurable (external-links: []) if (!string.IsNullOrEmpty(linkInline.Url)) { string upperUrl = linkInline.Url.ToUpperInvariant(); if (upperUrl.StartsWith("HTTP://", StringComparison.Ordinal) || upperUrl.StartsWith("HTTPS://", StringComparison.Ordinal) || upperUrl.StartsWith("MAILTO:", StringComparison.Ordinal)) { AddAttribute(linkInline, "rel", "nofollow"); } } } } WalkAndBindParseEvents(child); } }