コード例 #1
0
        public void BindValue(object value)
        {
            var parent = _targetElement.Parent();

            if (parent == null)
            {
                throw new NotSupportedException();
            }

            var text = (string)value;

            if (parent.ElementTextMode() == TextMode.Preformated)
            {
                parent.AddTextNode(_targetElement.NodesIndexOfSelf(), HtmlEncoding.HtmlEncode(text));
                _targetElement.Remove();
            }
            else
            {
                var encoded = HtmlEncoding.HtmlEncode(text);

                encoded = encoded.Replace("  ", "  ");

                if (encoded.EndsWith("  "))
                {
                    encoded = encoded.Substring(0, encoded.Length - 1) + " ";//如果末尾多出一个空格,则替换为 
                }
                encoded = encoded.Replace("\r\n", "\n").Replace("\r", "\n");

                encoded = encoded.Replace("\n", "<br />");

                _targetElement.ReplaceWith(encoded);
            }
        }
コード例 #2
0
ファイル: DocumentExtensions.cs プロジェクト: toddfsy/Jumony
        private static string CreateIdentity(IHtmlElement element, bool ancestorsCreate)
        {
            string parentId;

            var parentElement = element.Parent();

            if (parentElement != null)
            {
                parentId = Identity(parentElement);
                if (parentId == null)
                {
                    if (ancestorsCreate)
                    {
                        parentId = Identity(parentElement, true, true);
                    }
                    else
                    {
                        parentId = CreateIdentity(parentElement, false);
                    }
                }
            }
            else
            {
                if (element.Container is IHtmlDocument)
                {
                    parentId = null;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            var name = GetElementName(element);

            var builder = new StringBuilder();

            if (!string.IsNullOrEmpty(parentId))
            {
                builder.AppendFormat("{0}_", parentId);
            }

            builder.Append(name);

            if (element.Siblings().Where(e => GetElementName(e).EqualsIgnoreCase(GetElementName(element))).IsSingle())
            {
                return(builder.ToString());
            }



            var index = element.SiblingsBeforeSelf().Count(e => GetElementName(e).EqualsIgnoreCase(GetElementName(element)));

            builder.Append(index + 1);

            var identity = builder.ToString();

            return(EnsureUniqueness(identity, element.Document));
        }
コード例 #3
0
ファイル: CssRelativeSelector.cs プロジェクト: ajayumi/Jumony
    protected override bool IsEligible( ISelector leftSelector, IHtmlElement element )
    {
      var restrict = leftSelector as ContainerRestrict;
      if ( restrict != null )
        return restrict.RestrictContainer.Nodes().Contains( element );

      return leftSelector.IsEligibleBuffered( element.Parent() );
    }
コード例 #4
0
ファイル: CssRelativeSelector.cs プロジェクト: zpzgone/Jumony
        protected override bool IsEligible(ISelector leftSelector, IHtmlElement element)
        {
            var restrict = leftSelector as ContainerRestrict;

            if (restrict != null)
            {
                return(restrict.RestrictContainer.Nodes().Contains(element));
            }

            return(leftSelector.IsEligibleBuffered(element.Parent()));
        }
コード例 #5
0
ファイル: CssRelativeSelector.cs プロジェクト: zpzgone/Jumony
        protected override bool IsEligible(ISelector leftSelector, IHtmlElement element)
        {
            var restrict = leftSelector as ContainerRestrict;

            if (restrict != null)
            {
                return(element.IsDescendantOf(restrict.RestrictContainer));
            }


            var parant = element.Parent();

            //如果父级元素符合左选择器,或者父级元素符合本选择器。
            return(leftSelector.IsEligibleBuffered(parant) || this.IsEligibleBuffered(parant));
        }
コード例 #6
0
        /// <summary>
        /// 获取所有的父代元素以及元素自身
        /// </summary>
        /// <param name="element">要获取父代元素及自身的元素</param>
        /// <returns>元素的所有父代元素和自身的集合</returns>
        public static IEnumerable <IHtmlElement> AncestorsAndSelf(this IHtmlElement element)
        {
            EnsureAvaliable(element);

            while (true)
            {
                if (element == null)
                {
                    yield break;
                }

                yield return(element);

                element = element.Parent();
            }
        }
コード例 #7
0
        private static string CreateIdentity( IHtmlElement element, bool ancestorsCreate )
        {
            string parentId;

              var parentElement = element.Parent();
              if ( parentElement != null )
              {
            parentId = Identity( parentElement );
            if ( parentId == null )
            {
              if ( ancestorsCreate )
            parentId = Identity( parentElement, true, true );
              else
            parentId = CreateIdentity( parentElement, false );
            }
              }
              else
              {
            if ( element.Container is IHtmlDocument )
              parentId = null;
            else
              throw new InvalidOperationException();
              }

              var name = GetElementName( element );

              var builder = new StringBuilder();

              if ( !string.IsNullOrEmpty( parentId ) )
            builder.AppendFormat( "{0}_", parentId );

              builder.Append( name );

              string identity;

              if ( element.Siblings().Where( e => GetElementName( e ).EqualsIgnoreCase( GetElementName( element ) ) ).IsSingle() )
            identity = builder.ToString();

              var index = element.SiblingsBeforeSelf().Count( e => GetElementName( e ).EqualsIgnoreCase( GetElementName( element ) ) );
              builder.Append( index + 1 );

              identity = builder.ToString();
              return EnsureUniqueness( identity, element.Document );
        }
コード例 #8
0
        protected override bool IsEligible( ISelector leftSelector, IHtmlElement element )
        {
            var restrict = leftSelector as ContainerRestrict;
              if ( restrict != null )
            return element.IsDescendantOf( restrict.RestrictContainer );

              var parant = element.Parent();

              //如果父级元素符合左选择器,或者父级元素符合本选择器。
              return leftSelector.IsEligibleBuffered( parant ) || this.IsEligibleBuffered( parant );
        }