/// <inheritdoc /> public override async Task <IDocument> ExecuteAsync(KeyValuePair <string, string>[] args, string content, IDocument document, IExecutionContext context) { IMetadataDictionary arguments = args.ToDictionary( "Src", "Link", "Target", "Rel", "Alt", "Class", "Height", "Width"); XElement figure = new XElement( "figure", arguments.XAttribute("class")); // Image link XElement imageLink = arguments.XElement("a", "link", x => new[] { new XAttribute("href", context.GetLink(x)), arguments.XAttribute("target"), arguments.XAttribute("rel") }); // Image XElement image = arguments.XElement("img", "src", x => new[] { new XAttribute("src", context.GetLink(x)), arguments.XAttribute("alt"), arguments.XAttribute("height"), arguments.XAttribute("width") }); if (imageLink != null && image != null) { imageLink.Add(image); figure.Add(imageLink); } else if (image != null) { figure.Add(image); } // Caption if (content != null) { figure.Add(new XElement("figcaption", content)); } return(context.CreateDocument(await context.GetContentProviderAsync(figure.ToString()))); }
public override ShortcodeResult Execute(KeyValuePair <string, string>[] args, string content, IDocument document, IExecutionContext context) { IMetadataDictionary arguments = args.ToDictionary( Src, Link, Target, Rel, Alt, Class, Height, Width); XElement figure = new XElement( "figure", arguments.XAttribute(Class)); // Image link XElement imageLink = arguments.XElement("a", Link, x => new[] { new XAttribute("href", context.GetLink(x)), arguments.XAttribute(Target), arguments.XAttribute(Rel) }); // Image XElement image = arguments.XElement("img", Src, x => new[] { new XAttribute("src", context.GetLink(x)), arguments.XAttribute(Alt), arguments.XAttribute(Height), arguments.XAttribute(Width) }); if (imageLink != null && image != null) { imageLink.Add(image); figure.Add(imageLink); } else if (image != null) { figure.Add(image); } // Caption if (content != null) { figure.Add(new XElement("figcaption", content)); } return(figure.ToString()); }
public override ShortcodeResult Execute(KeyValuePair <string, string>[] args, string content, IDocument document, IExecutionContext context) { IMetadataDictionary arguments = args.ToDictionary( Src, Style); var style = arguments.GetString(Style) ?? "container"; XElement container = new XElement( "div", new XAttribute("class", style)); XElement figure = new XElement( "figure"); // Image XElement image = arguments.XElement("img", Src, x => new[] { new XAttribute("src", context.GetLink(x)) }); if (image is object) { figure.Add(image); } // Caption if (content is object) { figure.Add(new XElement("figcaption", content)); } container.Add(figure); return(container.ToString()); }