GetAttribute() public method

Locates element attribute by name using string comparison as specified by tree the element is in.
public GetAttribute ( string attributeName ) : AttributeNode
attributeName string Fully qualified attribute name
return AttributeNode
		public IEnumerable<ISuggestedAction> GetSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
		{
			AttributeNode ngController = element.GetAttribute("ng-controller") ?? element.GetAttribute("data-ng-controller");

            return new ISuggestedAction[] {
                new HtmlAngularControllerLightBulbAction(textView, textBuffer, element, ngController)
            };
		}
        public bool HasSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
        {
            if (!element.StartTag.Contains(caretPosition))
                return false;

            string url = (element.GetAttribute("src") ?? element.GetAttribute("href"))?.Value;

            if (string.IsNullOrEmpty(url) || (!url.Contains("://") && !url.StartsWith("//")))
                return false;

            return element.IsElement("style") || element.IsElement("script");
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            AttributeNode attr = element.GetAttribute("src") ?? element.GetAttribute("href");

            if (attr == null)
                return null;

            Uri url = NormalizeUrl(attr);

            if (url == null || (!attr.Value.StartsWith("//", StringComparison.Ordinal) && !attr.Value.Contains("://")))
                return null;

            return new RemoteDownloaderSmartTag(textView, textBuffer, element, attr);
        }
        public IEnumerable<ISuggestedAction> GetSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
        {
            AttributeNode src = element.GetAttribute("src");

            return new ISuggestedAction[] {
                    new HtmlBase64DecodeLightBulbAction(textView, textBuffer, element, src)
                };
        }
		public bool HasSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
		{
			if (element.Name != "img")
				return false;

			AttributeNode src = element.GetAttribute("src");

			return src != null && src.Value.Trim().Length > 0;
		}
        public bool Visit(ElementNode element, object parameter)
        {
            if (element.HasAttribute("id"))
            {
                var list = (HashSet<string>)parameter;
                list.Add(element.GetAttribute("id").Value);
            }

            return true;
        }
        public bool HasSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
        {
            if (!element.IsElement("img"))
                return false;

            AttributeNode src = element.GetAttribute("src");

            if (src == null)
                return false;

            return src.Value.StartsWith("data:image/", StringComparison.Ordinal);
        }
        public bool Visit(ElementNode element, object parameter)
        {
            if (_inputTypes.Contains(element.Name.ToLowerInvariant()))
            {
                var list = (HashSet<string>)parameter;
                var id = element.GetAttribute("id");

                if (id != null)
                    list.Add(id.Value);
            }

            return true;
        }
        public bool Visit(ElementNode element, object parameter)
        {
            if (element.Name == "label")
            {
                var list = (HashSet<string>)parameter;
                var forAttr = element.GetAttribute("for");

                if (forAttr != null)
                    list.Add(forAttr.Value);
            }

            return true;
        }
		public IEnumerable<ISuggestedAction> GetSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
		{
			AttributeNode src = element.GetAttribute("src");

            if (src.Value.StartsWith("data:image/", StringComparison.Ordinal))
			{
				yield return new HtmlBase64DecodeLightBulbAction(textView, textBuffer, element, src);
			}

			if (!src.Value.StartsWith("http:") && !src.Value.StartsWith("https:") && !src.Value.StartsWith("//"))
			{
				yield return new HtmlOptimizeImageLightBulbAction(textView, textBuffer, element, src); 
			}
		}
		public HtmlRemoveElementLightBulbAction(ITextView textView, ITextBuffer textBuffer, ElementNode element)
			: base(textView, textBuffer, element, element.Children.Count == 0 ? "Remove <" + element.StartTag.Name + "> tag" : "Remove <" + element.StartTag.Name + "> and Keep Children")
		{
			_src = element.GetAttribute("src", true);
		}
示例#12
0
	public static string AttrValue(ElementNode element, string attributeName, string defaultValue = null)
	{
		AttributeNode attr = element.GetAttribute(attributeName);
		return attr != null ? attr.Value : defaultValue;
	}