/// <summary> /// 转换 URI 与当前请求匹配 /// </summary> /// <param name="attribute"></param> protected virtual void ResolveUri(IHtmlAttribute attribute) { var uriValue = attribute.AttributeValue; if (string.IsNullOrWhiteSpace(uriValue))//对于空路径暂不作处理。 { return; } Uri absoluteUri; if (Uri.TryCreate(uriValue, UriKind.Absolute, out absoluteUri))//对于绝对 URI,不采取任何动作。 { return; } if (VirtualPathUtility.IsAbsolute(uriValue))//对于绝对路径,也不采取任何动作。 { return; } if (uriValue.StartsWith("#"))//若是本路径的片段链接,也不采取任何动作。 { return; } if (uriValue.StartsWith("?"))//若是本路径的查询链接,也不采取任何动作。 { return; } attribute.SetValue(ResolveVirtualPath(uriValue)); }
public override bool IsScriptValue(IHtmlAttribute attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } var elementName = attribute.Element.Name; switch (attribute.Name.ToLowerInvariant()) { case "onblur": case "onchange": case "onclick": case "ondbclick": case "onfocus": case "onkeydown": case "onkeypress": case "onkeyup": case "onload": case "onmousedown": case "onmousemove": case "onmouseout": case "onmouseover": case "onmouseup": case "onreset": case "onselect": case "onsubmit": case "onunload": return(true); } return(false); }
/// <summary> /// 构建 HtmlDomChangedEventArgs 对象 /// </summary> /// <param name="attribute">发生变化的属性</param> /// <param name="element">属性所属的元素</param> /// <param name="action">属性所发生的操作</param> public HtmlDomChangedEventArgs(IHtmlAttribute attribute, IHtmlElement element, HtmlDomChangedAction action) { IsAttributeChanged = true; Attribute = attribute; Container = element; Action = action; }
public override bool IsUriValue(IHtmlAttribute attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } var elementName = attribute.Element.Name; switch (attribute.Name.ToLowerInvariant()) { case "action": return(elementName.EqualsIgnoreCase("form")); case "background": return(elementName.EqualsIgnoreCase("body")); case "cite": return(elementName.EqualsIgnoreCase("blockquote") || elementName.EqualsIgnoreCase("q") || elementName.EqualsIgnoreCase("del") || elementName.EqualsIgnoreCase("ins")); case "classid": return(elementName.EqualsIgnoreCase("object")); case "codebase": return(elementName.EqualsIgnoreCase("object") || elementName.EqualsIgnoreCase("applet")); case "data": return(elementName.EqualsIgnoreCase("object")); case "href": return(elementName.EqualsIgnoreCase("a") || elementName.EqualsIgnoreCase("area") || elementName.EqualsIgnoreCase("link") || elementName.EqualsIgnoreCase("base")); case "longdesc": return(elementName.EqualsIgnoreCase("img") || elementName.EqualsIgnoreCase("frame") || elementName.EqualsIgnoreCase("iframe")); case "profile": return(elementName.EqualsIgnoreCase("head")); case "src": return(elementName.EqualsIgnoreCase("script") || elementName.EqualsIgnoreCase("input") || elementName.EqualsIgnoreCase("frame") || elementName.EqualsIgnoreCase("iframe") || elementName.EqualsIgnoreCase("img")); default: return(false); } }
public virtual IHtmlAttribute Create(string nameValueAttributesString) { string value = null; string openQuote = null; Match match = Regex.Match(nameValueAttributesString, _htmlHelper.GetNameValueAttributeRegex(_name)); if (match.Value.Length > 0 && !Regex.IsMatch(nameValueAttributesString, _htmlHelper.GetEmptyValueAttributeRegex(_name))) { // when value is not wraped whit quotes if (!match.Groups[2].Success) { // get string after equal symbol and first space value = nameValueAttributesString .SubStringToIndex(match.Index + match.Value.Length, nameValueAttributesString.IndexOf(" ") == -1 ? nameValueAttributesString.Length - 1 : nameValueAttributesString.IndexOf(" ")); } // when value is wraped whit quotes else { openQuote = match.Groups[2].Value; // get closing quote, closing quote is first after opened int closingQuoteIndex = nameValueAttributesString.IndexOf(openQuote, match.Groups[2].Index + 1); // get string between quotes value = nameValueAttributesString.Substring(match.Groups[2].Index + 1, (closingQuoteIndex - match.Groups[2].Index) - 1); } } IHtmlAttribute attribute = CreateInstance(); attribute.Value = value; attribute.WrapValueQuote = openQuote; return(attribute); }
/// <summary> /// 对元素属性进行绑定操作 /// </summary> /// <param name="attribute">要绑定的元素属性</param> /// <param name="context">绑定上下文</param> /// <returns>是否成功绑定</returns> public bool BindAttribute(IHtmlAttribute attribute, HtmlBindingContext context) { if (attribute.Name == "datacontext") { return(false); } var expression = AttributeExpression.ParseExpression(attribute); if (expression == null || !expression.Name.EqualsIgnoreCase("Binding")) { return(false); } var dataObject = GetDataObject(expression, context); if (dataObject == null) { attribute.Remove(); return(true); } string value = GetBindingValue(expression, dataObject); attribute.SetValue(value); return(true); }
private IBinding CreateAttributeBinding( IHtmlAttribute attribute ) { var args = BindingExpression.ParseExpression( attribute ); if ( args == null ) return null; return new Binding( attribute, args ); }
public void ReplaceAttributeValue(string Name, string Value) { IHtmlAttribute attribute = _attributes.FirstOrDefault(x => x.Name == Name); if (attribute != null) { attribute.Value = Value; } }
private void RemoveElement(IHtmlElement element, IHtmlAttribute attribute) { var classes = attribute.Value(); if (!string.IsNullOrEmpty(classes)) { Regulars.whiteSpaceSeparatorRegex.Split(classes).ForAll(c => RemoveElement(c, element)); } }
public void RemoveClass(string className) { IHtmlAttribute classAttribute = _attributes.FirstOrDefault(x => x.Name == "class"); if (classAttribute != null) { _attributes.Remove(classAttribute); } }
/// <summary> /// 当元素被移除属性 /// </summary> /// <param name="element"></param> /// <param name="attribute"></param> protected override void OnRemoveAttribute(IHtmlElement element, IHtmlAttribute attribute) { if (!attribute.Name.EqualsIgnoreCase("class")) { return; } RemoveElement(element, attribute); }
/// <summary> /// 获取属性值,与 AttributeValue 属性不同,Value 方法在属性对象为 null 时不会抛出异常 /// </summary> /// <param name="attribute">属性对象</param> /// <returns>属性值,如果属性对象为null,则返回null</returns> public static string Value(this IHtmlAttribute attribute) { if (attribute == null) { return(null); } return(attribute.AttributeValue); }
public void RemoveAttribute(string Name) { IHtmlAttribute attribute = _attributes.FirstOrDefault(x => x.Name == Name); if (attribute != null) { _attributes.Remove(attribute); } }
public void AddAttribute(IHtmlAttribute attribute) { if (attribute != null) { _attributes.RemoveAll(x => x.Name == attribute.Name); _attributes.Add(attribute); } }
public void AddClass(string className) { IHtmlAttribute classAttribute = _attributes.FirstOrDefault(x => x.Name == "class"); if (classAttribute != null) { classAttribute.Value = $"{classAttribute.Value ?? ""} {className}"; } _attributes.Add(new HtmlClassAttribute(className)); }
public void RemoveAttribute(IHtmlAttribute attribute) { var htmlAttribute = attribute.RawObject as HAP.HtmlAttribute; if (htmlAttribute == null) { throw new ArgumentException("attribute"); } htmlAttribute.Remove(); }
private IBinding CreateAttributeBinding(IHtmlAttribute attribute) { var args = BindingExpression.ParseExpression(attribute); if (args == null) { return(null); } return(new Binding(attribute, args)); }
private void RemoveElement(IHtmlElement element, IHtmlAttribute attribute) { var id = attribute.Value(); if (id == null) { return; } data.Remove(id); }
public void MergeAttributes(IHtmlAttribute[] Attributes) { foreach (var newAttribute in Attributes) { IHtmlAttribute existingAttribute = _attributes.FirstOrDefault(x => x.Name == newAttribute.Name); if (existingAttribute != null) { existingAttribute.Value = $"{existingAttribute.Value ?? ""} {newAttribute.Value}"; } } }
public void LoadTest_SetAttributeValue() { string htmlText1 = "<p>123<a target=\"_blank\" href=\"../../1.html\">000</a>456</p>"; string htmlText2 = "<p>123<a target=\"_self\" href=\"../../2.html\">000</a>456</p>"; IHtmlDocument document = HtmlAnalyzer.Load(htmlText1); IHtmlAttribute attribute = document.GetElementsByTagName("a").First().GetAttributesByName("target").First(); attribute.Value = "_self"; attribute = document.GetElementsByTagName("a").First().GetAttributesByName("href").First(); attribute.Value = "../../2.html"; Assert.AreEqual <string>(htmlText2, document.NodeHtml); }
/// <summary> /// 确保当前跟踪的样式是最新的 /// </summary> private void EnsureStyle() { lock (_element.SyncRoot) { var styleAttribute = _element.Attribute("style"); if (_style == null || styleAttribute != _attribute || (styleAttribute == null && _style.Any())) { _style = CssPropertyParser.ParseCssStyle(styleAttribute.Value().IfNull("")); _attribute = styleAttribute; } } }
/// <summary> /// 解析属性为绑定表达式 /// </summary> /// <param name="attribute">要解析的属性</param> /// <returns>绑定表达式</returns> public static AttributeExpression ParseExpression( IHtmlAttribute attribute ) { var expression = attribute.Value(); if ( expression == null ) return null; var match = attributeExpressionRegex.Match( expression ); if ( match == null || !match.Success ) return null; return ParseExpression( match ); }
public static IDictionary<string, string> ParseExpression( IHtmlAttribute attribute ) { var expression = attribute.Value(); if ( expression == null ) return null; var match = bindingExpressionRegex.Match( expression ); if ( match == null || !match.Success ) return null; return ParseExpression( match ); }
public void ToogleClass(string className) { IHtmlAttribute classAttribute = _attributes.FirstOrDefault(x => x.Name == "class"); if (classAttribute != null) { RemoveClass(className); } else { AddClass(className); } }
/// <summary> /// 移除指定的属性 /// </summary> /// <param name="attribute">要移除的属性</param> public void RemoveAttribute(IHtmlAttribute attribute) { lock ( _sync ) { unchecked { _version++; } var domAttribute = attribute as DomAttribute; if (domAttribute == null) { throw new InvalidOperationException(); } domAttribute.Remove(); } }
/// <summary> /// 绑定元素样式 /// </summary> /// <param name="element">要处理的元素</param> /// <param name="styleAttributes">样式属性</param> private static void BindElementStyles( IHtmlElement element, IHtmlAttribute[] styleAttributes ) { foreach ( var attribute in styleAttributes ) { var value = attribute.AttributeValue; var name = attribute.Name.Substring( styleAttributePrefix.Length ); attribute.Remove(); if ( string.IsNullOrEmpty( value ) ) continue; else element.Style( name, value ); } }
/// <summary> /// 尝试从 DOM 中移除此属性 /// </summary> /// <param name="attribute">要被移除的属性</param> /// <exception cref="System.NotSupportedException">若文档不支持修改 DOM 结构</exception> /// <remarks> /// 若属性不存在(即为 null),则此方法不执行任何操作 /// </remarks> public static void Remove(this IHtmlAttribute attribute) { if (attribute == null) { return; } if (attribute.Element == null) { throw new InvalidOperationException(); } var modifier = EnsureModifiable(attribute.Element); modifier.RemoveAttribute(attribute); }
/// <summary> /// 转换 URI 与当前请求匹配 /// </summary> /// <param name="attribute">HTML 属性</param> /// <param name="baseVirtualPath">基路径</param> public void ResolveUri(IHtmlAttribute attribute, string baseVirtualPath) { if (attribute == null) { throw new ArgumentNullException("attribute"); } if (baseVirtualPath == null) { throw new ArgumentNullException("baseVirtualPath"); } var uriValue = attribute.AttributeValue; if (string.IsNullOrWhiteSpace(uriValue))//对于空路径暂不作处理。 { return; } Uri absoluteUri; if (Uri.TryCreate(uriValue, UriKind.Absolute, out absoluteUri))//对于绝对 URI,不采取任何动作。 { return; } if (VirtualPathUtility.IsAbsolute(uriValue))//对于绝对路径,也不采取任何动作。 { return; } if (uriValue.StartsWith("#"))//若是本路径的片段链接,也不采取任何动作。 { return; } if (uriValue.StartsWith("?"))//若是本路径的查询链接,也不采取任何动作。 { return; } attribute.SetValue(ResolveVirtualPath(baseVirtualPath, uriValue)); }
public static IDictionary <string, string> ParseExpression(IHtmlAttribute attribute) { var expression = attribute.Value(); if (expression == null) { return(null); } var match = bindingExpressionRegex.Match(expression); if (match == null || !match.Success) { return(null); } return(ParseExpression(match)); }
/// <summary> /// 解析属性为绑定表达式 /// </summary> /// <param name="attribute">要解析的属性</param> /// <returns>绑定表达式</returns> public static AttributeExpression ParseExpression(IHtmlAttribute attribute) { var expression = attribute.Value(); if (expression == null) { return(null); } var match = attributeExpressionRegex.Match(expression); if (match == null || !match.Success) { return(null); } return(ParseExpression(match)); }
/// <summary> /// 设置属性的值,这会产生一个新的属性,并返回 /// </summary> /// <param name="attribute">要设置值的属性</param> /// <param name="value">设置的值</param> /// <returns>所创建的新属性</returns> public static IHtmlAttribute SetValue(this IHtmlAttribute attribute, string value) { if (attribute == null) { throw new ArgumentNullException("attribute"); } var element = attribute.Element; var name = attribute.Name; if (element == null) { throw new InvalidOperationException(); } attribute.Remove(); return(element.AddAttribute(name, value)); }
/// <summary> /// 进行属性绑定 /// </summary> /// <param name="attribute">要绑定的属性</param> protected virtual void BindAttribute(IHtmlAttribute attribute) { var expression = BindingExpression.ParseExpression(attribute.Value()); if (expression == null) { return; } var value = GetValue(expression); if (value == null) { attribute.Remove(); } else { attribute.SetValue(value.ToString()); } }
/// <summary> /// Create html attribute string. /// </summary> /// <param name="attribute">Object of type IHtmlAttribute, for convert to html attribute string.</param> /// <returns>String represent specified atribute.</returns> private string CreateAtribute(IHtmlAttribute attribute) { string attributesString = String.Empty; if (attribute.Value == null) { attributesString += $"{attribute.Name} "; } else { if ((attribute.Value.StartsWith("'") && attribute.Value.EndsWith("'")) || (attribute.Value.StartsWith("\"") && attribute.Value.EndsWith("\"")) || attribute.WrapValueQuote == null) { attributesString += $"{attribute.Name}={attribute.Value} "; } else { attributesString += $"{attribute.Name}={attribute.WrapValueQuote}{attribute.Value}{attribute.WrapValueQuote} "; } } return(attributesString.TrimEnd().TrimStart()); }
public override bool IsMarkupAttribute(IHtmlAttribute attribute) { switch (attribute.Name.ToLowerInvariant()) { case "checked": case "compact": case "declare": case "defer": case "disabled": case "ismap": case "multiple": case "nohref": case "noresize": case "noshade": case "nowrap": case "readonly": case "selected": return(true); } return(false); }
/// <summary> /// 对元素属性进行绑定操作 /// </summary> /// <param name="attribute">要绑定的元素属性</param> /// <param name="context">绑定上下文</param> /// <returns>是否成功绑定</returns> public bool BindAttribute( IHtmlAttribute attribute, HtmlBindingContext context ) { if ( attribute.Name == "datacontext" ) return false; var expression = AttributeExpression.ParseExpression( attribute ); if ( expression == null || !expression.Name.EqualsIgnoreCase( "Binding" ) ) return false; var dataObject = GetDataObject( expression, context ); if ( dataObject == null ) { attribute.Remove(); return true; } string value = GetBindingValue( expression, dataObject ); attribute.SetValue( value ); return true; }
public override bool IsMarkupAttribute( IHtmlAttribute attribute ) { switch ( attribute.Name.ToLowerInvariant() ) { case "checked": case "compact": case "declare": case "defer": case "disabled": case "ismap": case "multiple": case "nohref": case "noresize": case "noshade": case "nowrap": case "readonly": case "selected": return true; } return false; }
public override bool IsUriValue( IHtmlAttribute attribute ) { if ( attribute == null ) throw new ArgumentNullException( "attribute" ); var elementName = attribute.Element.Name; switch ( attribute.Name.ToLowerInvariant() ) { case "action": return elementName.EqualsIgnoreCase( "form" ); case "background": return elementName.EqualsIgnoreCase( "body" ); case "cite": return elementName.EqualsIgnoreCase( "blockquote" ) || elementName.EqualsIgnoreCase( "q" ) || elementName.EqualsIgnoreCase( "del" ) || elementName.EqualsIgnoreCase( "ins" ); case "classid": return elementName.EqualsIgnoreCase( "object" ); case "codebase": return elementName.EqualsIgnoreCase( "object" ) || elementName.EqualsIgnoreCase( "applet" ); case "data": return elementName.EqualsIgnoreCase( "object" ); case "href": return elementName.EqualsIgnoreCase( "a" ) || elementName.EqualsIgnoreCase( "area" ) || elementName.EqualsIgnoreCase( "link" ) || elementName.EqualsIgnoreCase( "base" ); case "longdesc": return elementName.EqualsIgnoreCase( "img" ) || elementName.EqualsIgnoreCase( "frame" ) || elementName.EqualsIgnoreCase( "iframe" ); case "profile": return elementName.EqualsIgnoreCase( "head" ); case "src": return elementName.EqualsIgnoreCase( "script" ) || elementName.EqualsIgnoreCase( "input" ) || elementName.EqualsIgnoreCase( "frame" ) || elementName.EqualsIgnoreCase( "iframe" ) || elementName.EqualsIgnoreCase( "img" ); default: return false; } }
public override bool IsScriptValue( IHtmlAttribute attribute ) { if ( attribute == null ) throw new ArgumentNullException( "attribute" ); var elementName = attribute.Element.Name; switch ( attribute.Name.ToLowerInvariant() ) { case "onblur": case "onchange": case "onclick": case "ondbclick": case "onfocus": case "onkeydown": case "onkeypress": case "onkeyup": case "onload": case "onmousedown": case "onmousemove": case "onmouseout": case "onmouseover": case "onmouseup": case "onreset": case "onselect": case "onsubmit": case "onunload": return true; } return false; }
public void RemoveAttribute( IHtmlAttribute attribute ) { var htmlAttribute = attribute.RawObject as HAP.HtmlAttribute; if ( htmlAttribute == null ) throw new ArgumentException( "attribute" ); htmlAttribute.Remove(); }
private bool MarkupAttribute( IHtmlAttribute attribute ) { return attribute.Document.HtmlSpecification.IsMarkupAttribute( attribute ); }
public override bool IsMarkupAttribute( IHtmlAttribute attribute ) { throw new NotImplementedException(); }
/// <summary> /// 判断一个属性是否为标记属性。 /// </summary> /// <param name="attribute">要检查的属性</param> /// <returns>是否为标记属性</returns> public abstract bool IsMarkupAttribute( IHtmlAttribute attribute );
/// <summary> /// 判断一个属性值的值是否应被视为脚本。 /// </summary> /// <param name="attribute">要检查的属性</param> /// <returns>其值是否应被视为脚本</returns> public abstract bool IsScriptValue( IHtmlAttribute attribute );
/// <summary> /// 判断一个属性值的值是否应被视为URI。 /// </summary> /// <param name="attribute">要检查的属性</param> /// <returns>其值是否应被视为URI</returns> public abstract bool IsUriValue( IHtmlAttribute attribute );
/// <summary> /// 确保当前跟踪的样式是最新的 /// </summary> private void EnsureStyle() { lock ( _element.SyncRoot ) { var styleAttribute = _element.Attribute( "style" ); if ( _style == null || styleAttribute != _attribute || (styleAttribute == null && _style.Any()) ) { _style = CssPropertyParser.ParseCssStyle( styleAttribute.Value().IfNull( "" ) ); _attribute = styleAttribute; } } }
/// <summary> /// 构建 HtmlDomChangedEventArgs 对象 /// </summary> /// <param name="attribute">发生变化的属性</param> /// <param name="element">属性所属的元素</param> /// <param name="action">属性所发生的操作</param> public HtmlDomChangedEventArgs( IHtmlAttribute attribute, IHtmlElement element, HtmlDomChangedAction action ) { IsAttributeChanged = true; Attribute = attribute; Container = element; Action = action; }
static void CleanAttributeValue(IHtmlAttribute attribute) { var hasMatch = true; while(hasMatch) { hasMatch = false; // basic if(Regex.IsMatch(attribute.Value, @"/\*([a]*|[^a]*)\*/", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"/\*([a]*|[^a]*)\*/", "", RegexOptions.IgnoreCase); if(Regex.IsMatch(attribute.Value, @"\s*j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:.*", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"\s*j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:.*", "", RegexOptions.IgnoreCase); if(Regex.IsMatch(attribute.Value, @"\s*s\s*c\s*r\s*i\s*p\s*t\s*", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"\s*s\s*c\s*r\s*i\s*p\s*t\s*", "", RegexOptions.IgnoreCase); // style attr if(attribute.Name == "style") { if(Regex.IsMatch(attribute.Value, @"\s*e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"\s*e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*", "", RegexOptions.IgnoreCase); if(Regex.IsMatch(attribute.Value, @"\s*b\s*e\s*h\s*a\s*v\s*i\s*o\s*r\s*", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"\s*b\s*e\s*h\s*a\s*v\s*i\s*o\s*r\s*", "", RegexOptions.IgnoreCase); if(Regex.IsMatch(attribute.Value, @"-[a-zA-Z\s]+-", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"-[a-zA-Z\s]+-", "", RegexOptions.IgnoreCase); } // media attr if(attribute.Name == "media") { if(Regex.IsMatch(attribute.Value, @"-[a-zA-Z\s]+-", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"-[a-zA-Z\s]+-", "", RegexOptions.IgnoreCase); } // href & src attrs if(attribute.Name == "href" || attribute.Name == "src") { if(Regex.IsMatch(attribute.Value, @"\s*m\s*o\s*c\s*h\s*a\s*", RegexOptions.IgnoreCase)) hasMatch = true; attribute.Value = Regex.Replace(attribute.Value, @"\s*m\s*o\s*c\s*h\s*a\s*", "", RegexOptions.IgnoreCase); } } attribute.Value = HttpUtility.HtmlEncode(attribute.Value); // HtmlEntity Escape var sbAttriuteValue = new StringBuilder(); foreach(char c in attribute.Value.ToCharArray()) { sbAttriuteValue.Append(EncodeCharacterToHtmlEntityEscape(c)); } attribute.Value = sbAttriuteValue.ToString(); }
/// <summary> /// 移除指定的属性 /// </summary> /// <param name="attribute">要移除的属性</param> public void RemoveAttribute( IHtmlAttribute attribute ) { lock ( _sync ) { unchecked { _version++; } var domAttribute = attribute as DomAttribute; if ( domAttribute == null ) throw new InvalidOperationException(); domAttribute.Remove(); } }
/// <summary> /// 转换 URI 与当前请求匹配 /// </summary> /// <param name="attribute">HTML 属性</param> /// <param name="baseVirtualPath">基路径</param> public void ResolveUri( IHtmlAttribute attribute, string baseVirtualPath ) { if ( attribute == null ) throw new ArgumentNullException( "attribute" ); if ( baseVirtualPath == null ) throw new ArgumentNullException( "baseVirtualPath" ); var uriValue = attribute.AttributeValue; if ( string.IsNullOrWhiteSpace( uriValue ) )//对于空路径暂不作处理。 return; Uri absoluteUri; if ( Uri.TryCreate( uriValue, UriKind.Absolute, out absoluteUri ) )//对于绝对 URI,不采取任何动作。 return; if ( VirtualPathUtility.IsAbsolute( uriValue ) )//对于绝对路径,也不采取任何动作。 return; if ( uriValue.StartsWith( "#" ) )//若是本路径的片段链接,也不采取任何动作。 return; if ( uriValue.StartsWith( "?" ) )//若是本路径的查询链接,也不采取任何动作。 return; attribute.SetValue( ResolveVirtualPath( baseVirtualPath, uriValue ) ); }
/// <summary> /// 绑定元素样式类 /// </summary> /// <param name="element">要处理的元素</param> /// <param name="classAttributes">样式类属性</param> private static void BindElementClasses( IHtmlElement element, IHtmlAttribute[] classAttributes ) { foreach ( var attribute in classAttributes ) { var value = attribute.AttributeValue; var name = attribute.Name.Substring( classAttributePrefix.Length ); attribute.Remove(); if ( string.IsNullOrEmpty( value ) ) continue; else if ( value.EqualsIgnoreCase( "false" ) ) element.Class().Remove( name ); else element.Class().Add( name ); } }
public override bool IsScriptValue( IHtmlAttribute attribute ) { throw new NotImplementedException(); }
/// <summary> /// 进行属性绑定 /// </summary> /// <param name="attribute">要绑定的属性</param> private void BindAttribute( IHtmlAttribute attribute ) { Binders.FirstOrDefault( b => b.BindAttribute( attribute, this ) ); }