Example #1
0
    public TranslationTerm( IHtmlTextNode textNode )
    {
      TextNode = textNode;
      var specification = textNode.Document.HtmlSpecification;

      if ( !textNode.Ancestors().Any( e => e.ElementTextMode() == TextMode.Preformated ) )
        SourceTerm = whitespaceRegex.Replace( textNode.HtmlText, " " );

      else
        SourceTerm = textNode.HtmlText;
    }
Example #2
0
 public TranslationTerm(IHtmlTextNode textNode)
 {
     TextNode = textNode;
     if (!textNode.Ancestors().Any(e => HtmlSpecification.preformatedElements.Contains(e.Name, StringComparer.OrdinalIgnoreCase)))
     {
         SourceTerm     = whitespaceRegex.Replace(textNode.HtmlText, " ");
         TranslatedTerm = whitespaceRegex.Replace(textNode.HtmlText, " ");
     }
     else
     {
         SourceTerm     = textNode.HtmlText;
         TranslatedTerm = textNode.HtmlText;
     }
 }
Example #3
0
 public TranslationTerm( IHtmlTextNode textNode )
 {
   TextNode = textNode;
   if ( !textNode.Ancestors().Any( e => HtmlSpecification.preformatedElements.Contains( e.Name, StringComparer.OrdinalIgnoreCase ) ) )
   {
     SourceTerm = whitespaceRegex.Replace( textNode.HtmlText, " " );
     TranslatedTerm = whitespaceRegex.Replace( textNode.HtmlText, " " );
   }
   else
   {
     SourceTerm = textNode.HtmlText;
     TranslatedTerm = textNode.HtmlText;
   }
 }
Example #4
0
        public TranslationTerm(IHtmlTextNode textNode)
        {
            TextNode = textNode;
            var specification = textNode.Document.HtmlSpecification;

            if (!textNode.Ancestors().Any(e => e.ElementTextMode() == TextMode.Preformated))
            {
                SourceTerm = whitespaceRegex.Replace(textNode.HtmlText, " ");
            }

            else
            {
                SourceTerm = textNode.HtmlText;
            }
        }
        /// <summary>
        /// 在后面添加节点的副本
        /// </summary>
        /// <param name="node">要在其后面添加副本的节点</param>
        /// <param name="textNode">要创作副本的节点</param>
        /// <returns>添加后的节点</returns>
        public static IHtmlTextNode AddCopyAfterSelf( this IHtmlNode node, IHtmlTextNode textNode )
        {
            if ( node == null )
            throw new ArgumentNullException( "node" );

              if ( textNode == null )
            throw new ArgumentNullException( "textNode" );

              var container = node.Container;

              lock ( container.SyncRoot )
              {
            return container.AddCopy( node.NodesIndexOfSelf() + 1, textNode );
              }
        }
Example #6
0
        /// <summary>
        /// 添加节点的副本
        /// </summary>
        /// <param name="container">要添加副本的容器</param>
        /// <param name="textNode">要创作副本的节点</param>
        /// <returns>添加后的节点</returns>
        public static IHtmlTextNode AddCopy(this IHtmlContainer container, IHtmlTextNode textNode)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (textNode == null)
            {
                throw new ArgumentNullException("textNode");
            }


            lock (container.SyncRoot)
            {
                return(AddCopy(container, container.Nodes().Count(), textNode));
            }
        }
Example #7
0
        /// <summary>
        /// 判断一个文本节点是不是全部由空白字符组成
        /// </summary>
        /// <param name="textNode">要判断的文本节点</param>
        /// <returns>是否全部是空白字符</returns>
        public static bool IsWhiteSpace(this IHtmlTextNode textNode)
        {
            if (textNode == null)
            {
                throw new ArgumentNullException("textNode");
            }


            if (whitespaceRegex.Match(textNode.HtmlText).Length == textNode.HtmlText.Length)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
Example #8
0
        /// <summary>
        /// 在前面添加节点的副本
        /// </summary>
        /// <param name="node">要在其前面添加副本的节点</param>
        /// <param name="textNode">要创作副本的节点</param>
        /// <returns>添加后的节点</returns>
        public static IHtmlTextNode AddCopyBeforeSelf(this IHtmlNode node, IHtmlTextNode textNode)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (textNode == null)
            {
                throw new ArgumentNullException("textNode");
            }


            var container = node.Container;

            lock (container.SyncRoot)
            {
                return(container.AddCopy(node.NodesIndexOfSelf(), textNode));
            }
        }
Example #9
0
        private static bool IsTranslatable(IHtmlTextNode textNode)
        {
            if (textNode.IsWhiteSpace())
            {
                return(false);
            }

            if (textNode is IHtmlSpecial)
            {
                return(false);
            }

            if (textNode.Ancestors().Any(e => e.Name.EqualsIgnoreCase("partial") || e.Name.EqualsIgnoreCase("head")))
            {
                return(false);
            }

            if (textNode.Parent() != null && HtmlSpecification.nonTextElements.Contains(textNode.Parent().Name, StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Example #10
0
        private static bool IsTranslatable(IHtmlTextNode textNode)
        {
            if (textNode.IsWhiteSpace())
            {
                return(false);
            }

            if (textNode is IHtmlSpecial)
            {
                return(false);
            }

            if (textNode.Ancestors().Any(e => e.Name.EqualsIgnoreCase("partial") || e.Name.EqualsIgnoreCase("head")))
            {
                return(false);
            }

            if (textNode.Parent() != null && textNode.ElementTextMode() == TextMode.NonText)
            {
                return(false);
            }

            return(true);
        }
Example #11
0
    private static bool IsTranslatable( IHtmlTextNode textNode )
    {
      if ( textNode.IsWhiteSpace() )
        return false;

      if ( textNode is IHtmlSpecial )
        return false;

      if ( textNode.Ancestors().Any( e => e.Name.EqualsIgnoreCase( "partial" ) || e.Name.EqualsIgnoreCase( "head" ) ) )
        return false;

      if ( textNode.Parent() != null && textNode.ElementTextMode() == TextMode.NonText )
        return false;

      return true;
    }
Example #12
0
    private static bool IsTranslatable( IHtmlTextNode textNode )
    {
      if ( textNode.IsWhiteSpace() )
        return false;

      if ( textNode is IHtmlSpecial )
        return false;

      if ( textNode.Ancestors().Any( e => e.Name.EqualsIgnoreCase( "partial" ) || e.Name.EqualsIgnoreCase( "head" ) ) )
        return false;

      if ( textNode.Parent() != null && HtmlSpecification.nonTextElements.Contains( textNode.Parent().Name, StringComparer.OrdinalIgnoreCase ) )
        return false;

      return true;
    }
Example #13
0
        /// <summary>
        /// 添加节点的副本
        /// </summary>
        /// <param name="container">要添加副本的容器</param>
        /// <param name="index">添加的位置</param>
        /// <param name="textNode">要创作副本的节点</param>
        /// <returns>添加后的节点</returns>
        public static IHtmlTextNode AddCopy(this IHtmlContainer container, int index, IHtmlTextNode textNode)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (textNode == null)
            {
                throw new ArgumentNullException("textNode");
            }


            return(container.AddTextNode(index, textNode.HtmlText));
        }
Example #14
0
 /// <summary>
 /// 创建文本节点的副本
 /// </summary>
 /// <param name="factory">用于创建文本节点的构建器</param>
 /// <param name="textNode">需要被创建副本的文本节点</param>
 /// <returns>文本节点的未分配副本</returns>
 public static IFreeTextNode MakeCopy(this IHtmlNodeFactory factory, IHtmlTextNode textNode)
 {
     return(factory.CreateTextNode(textNode.HtmlText));
 }