private void UpdateLinks(MarkdownObject markdownObject) { switch (markdownObject) { case TabTitleBlock _: break; case LinkInline linkInline: linkInline.Url = linkInline.IsImage ? _context.GetImageLink(linkInline.Url, linkInline, null) : _context.GetLink(linkInline.Url, linkInline); foreach (var subBlock in linkInline) { UpdateLinks(subBlock); } break; case ContainerBlock containerBlock: foreach (var subBlock in containerBlock) { UpdateLinks(subBlock); } break; case LeafBlock leafBlock when leafBlock.Inline != null: foreach (var subInline in leafBlock.Inline) { UpdateLinks(subInline); } break; case ContainerInline containerInline: foreach (var subInline in containerInline) { UpdateLinks(subInline); } break; default: break; } }
public bool TryProcessAttributes(IDictionary <string, string> attributes, out HtmlAttributes htmlAttributes, out IDictionary <string, string> renderProperties, Action <string> logError, Action <string> logWarning, MarkdownObject markdownObject) { htmlAttributes = null; renderProperties = new Dictionary <string, string>(); var src = string.Empty; var alt = string.Empty; var type = string.Empty; var loc_scope = string.Empty; foreach (var attribute in attributes) { var name = attribute.Key; var value = attribute.Value; switch (name) { case "alt-text": alt = value; break; case "type": type = value; break; case "loc-scope": loc_scope = value; break; case "source": src = value; break; case "border": break; case "lightbox": break; case "link": break; default: logError($"Image reference '{src}' is invalid per the schema. Unexpected attribute: '{name}'."); return(false); } } if (string.IsNullOrEmpty(type)) { type = "content"; } if (string.IsNullOrEmpty(src)) { logError("source is a required attribute. Please ensure you have specified a source attribute."); } if (string.IsNullOrEmpty(alt) && type != "icon") { logError("alt-text is a required attribute. Please ensure you have specified an alt-text attribute."); } // add loc scope missing/invalid validation here if ((string.IsNullOrEmpty(alt) && type != "icon") || string.IsNullOrEmpty(src)) { return(false); } htmlAttributes = new HtmlAttributes(); // alt is allowed to be empty for icon type image if (string.IsNullOrEmpty(alt) && type == "icon") { htmlAttributes.AddProperty("src", _context.GetLink(src, markdownObject)); } else { htmlAttributes.AddProperty("src", _context.GetImageLink(src, markdownObject, alt)); } if (type == "icon") { htmlAttributes.AddProperty("role", "presentation"); } else { htmlAttributes.AddProperty("alt", alt); } var id = GetHtmlId(markdownObject); if (type == "complex") { htmlAttributes.AddProperty("aria-describedby", id); } return(true); }