Example #1
0
 public HtmlNode GetNodeByContent(string p)
 {
     if (Children.Count > 0)
     {
         HtmlNode selected = null;
         foreach (HtmlNode child in Children)
         {
             selected = child.GetNodeByContent(p);
             if (selected != null)
             {
                 break;
             }
         }
         return(selected);
     }
     else
     {
         if (InnerText.Contains(p))
         {
             return(this);
         }
         else
         {
             return(null);
         }
     }
 }
Example #2
0
        public Word[] GetElements()
        {
            var elements = InnerText.Split(Splitters, StringSplitOptions.RemoveEmptyEntries);

            Word[] wordElements = new Word[elements.Length];
            for (int index = 0; index < elements.Length; index++)
            {
                var element = elements[index];
                wordElements[index] = new Word(element);
            }
            return(wordElements);
        }
        /// <summary>
        /// Evaluate the equivalence of objects.
        /// </summary>
        /// <param name="obj">Target object.</param>
        /// <returns>Object equivalence.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            if (this == obj)
            {
                return(true);
            }

            var element   = (AbstractSavannahXmlNode)obj;
            var collector = new BoolCollector();

            collector.ChangeBool(TagName, TagName == element.TagName);
            collector.ChangeBool(InnerText, InnerText.Equals(element.InnerText));

            return(collector.Value);
        }
Example #4
0
        public List <HtmlNode> GetNodesByContent(string p, List <HtmlNode> nodes = null)
        {
            if (nodes == null)
            {
                nodes = new List <HtmlNode>();
            }

            if (Children.Count > 0)
            {
                foreach (HtmlNode child in Children)
                {
                    child.GetNodesByContent(p, nodes);
                }
                return(nodes);
            }
            else
            {
                if (InnerText.Contains(p))
                {
                    nodes.Add(this);
                }
                return(nodes);
            }
        }
Example #5
0
 public override int GetHashCode()
 {
     return(InnerText.GetHashCode());
 }
 public void Visit(InnerText text)
 {
     // No op
 }
        public string GetAllText(bool keepTextTags, bool trim)
        {
            string result = null;

            if (GetTagName() == "script" ||
                GetTagName() == "style")
            {
                return(result);
            }

            if (keepTextTags)
            {
                if (GetTagName() == "br")
                {
                    result += "<br/>";
                }
                if (GetTagName() == "p")
                {
                    result += "<p>";
                }
                if (GetTagName() == "blockquote")
                {
                    result += "<blockquote>";
                }
                if (GetTagName() == "b")
                {
                    result += "<b>";
                }
                if (GetTagName() == "strong")
                {
                    result += "<strong>";
                }
            }

            if (!trim)
            {
                result += InnerText;
            }
            else
            {
                if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(InnerText))
                {
                    result += " " + InnerText.Trim();
                }
                else if (!string.IsNullOrEmpty(InnerText))
                {
                    result += InnerText.Trim();
                }
            }


            if (ChildCount > 0)
            {
                foreach (HtmlElement element in Childs)
                {
                    string childText = element.GetAllText(keepTextTags, trim);
                    if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(childText))
                    {
                        result += " " + childText.Trim();
                    }
                    else if (!string.IsNullOrEmpty(childText))
                    {
                        result += childText.Trim();
                    }
                }
            }

            if (keepTextTags)
            {
                if (GetTagName() == "p")
                {
                    result += "</p>";
                }
                if (GetTagName() == "blockquote")
                {
                    result += "</blockquote>";
                }
                if (GetTagName() == "b")
                {
                    result += "</b>";
                }
                if (GetTagName() == "strong")
                {
                    result += "</strong>";
                }
            }

            return(result);
        }
Example #8
0
 public byte[] GetOwnData()
 {
     return(Convert.FromBase64String(InnerText.Trim()));
 }
Example #9
0
        public string Compile(int tabs = 0, bool iret = false)
        {
            var    tbs = DoTabs(tabs);
            string ret = "";

            if (assignTo != "")
            {
                var func = (Function)assingBlock.SymbolTable.Get(assignTo);
                if (func.attributes?.Where(x => x.GetName(true) == "Debug").Count() > 0)
                {
                    ret += "/*Component: " + Name + "*/";
                }
            }

            var _oname = Name;

            /*if (_rewr.ContainsKey(_name) && (!iret || _inner.Count > 0 ))
             *  _name = _rewr[_name];*/

            var   txt     = InnerText.Replace("\r\n", "").Replace("\t", "");
            Regex re      = new Regex(@"\{(.*)\}");
            var   replace = re.Replace(txt, x =>
            {
                var s    = x.Value.Substring(1, x.Value.Length - 2);
                var find = assingBlock.SymbolTable.Get(s);
                if (assingBlock.assingToType?.assignTo != null)
                {
                    var _class = assingBlock.SymbolTable.Get(assingBlock.assingToType?.assignTo);
                    if (_class is Class cls)
                    {
                        var parent = cls.GetParent();
                        find       = parent.assingBlock.SymbolTable.Get(s);
                    }
                }
                if (find is Variable)
                {
                    return("\"+" + s + "+\"");
                }
                else if (find is Function)
                {
                    return("fun");
                }
                else if (find is Assign fa)
                {
                    return("\"+" + s + "+\"");
                }
                else if (find is Class)
                {
                    return("\"+" + s.Replace("this", "_this") + "+\"");
                }
                return("");
            });

            var pou = "";

            foreach (var p in Arguments)
            {
                if (p.Value is Assign pa)
                {
                    if (pa.Left is Variable pav)
                    {
                        var cml = p.Value.Compile();
                        pou += "" + p.Key + ": " + cml.Replace("this", "_this") + ", ";
                        //args += "{name: \"" + pav.Value + "\", value: " + cml + "}, ";
                    }
                }
                else if (p.Value is Variable pv)
                {
                    var cml = p.Value.Compile();
                    if (Char.IsLetterOrDigit(p.Key[0]))
                    {
                        pou += "" + p.Key + ": ";
                    }
                    else
                    {
                        pou += "\"" + p.Key + "\": ";
                    }
                    if ((p.Key.Substring(0, 2) != "on" && cml.Contains("this")))
                    {
                        pou += "function(){ return " + cml.Replace("this", "_this") + "; }, ";
                    }
                    else
                    {
                        pou += cml.Replace("this", "_this") + ", ";
                    }
                    //args += "{name: \"" + pv.Value + "\", value: " + cml + "}, ";
                }
                else if (p.Value is Lambda arl)
                {
                    arl.endit       = false;
                    arl.replaceThis = "_this";
                    var cml = arl.Compile();
                    if (Char.IsLetterOrDigit(p.Key[0]))
                    {
                        pou += "" + p.Key + ": " + cml.Replace("this", "_this").Replace("__this", "_this") + ", ";
                    }
                    else
                    {
                        pou += "\"" + p.Key + "\": " + cml.Replace("this", "_this").Replace("__this", "_this") + ", ";
                    }
                }
                else
                {
                    if (Char.IsLetterOrDigit(p.Key[0]))
                    {
                        pou += "" + p.Key + ": " + p.Value.Compile().Replace("this", "_this") + ", ";
                    }
                    else
                    {
                        pou += "\"" + p.Key + "\": " + p.Value.Compile().Replace("this", "_this") + ", ";
                    }
                }
            }

            if (pou != "")
            {
                pou = pou.Substring(0, pou.Length - 2);
            }

            if (Name == "")
            {
                var tb0 = DoTabs(iret ? 0 : tabs);
                if (Fun == null)
                {
                    ret += tb0 + "\"" + replace + "\"";
                }
                else
                {
                    if (Fun is UnaryOp fu && fu.Op == "call")
                    {
                        fu.endit = false;
                        //ret += tb0 + Fun.Compile().Replace("this", "_this");
                    }
                    //else
                    ret += tb0 + "function(){ return " + Fun.Compile().Replace("this", "_this").Replace("__this", "_this") + "; }";
                }
            }
            else if (InnerComponent.Count > 0)
            {
                var tb0 = DoTabs(iret ? 0 : tabs);
                var tb1 = DoTabs(iret ? tabs + 2 : tabs + 1);
                var hm0 = iret ? tabs + 2 : tabs + 1;

                if (_base.Contains(_oname) || _oname.ToLower() == _oname)
                {
                    var f = assingBlock.SymbolTable.Get(Name);
                    if (f is Error)
                    {
                        ret += tb0 + "new Pyr.createElement(\r\n" + tb1 + "\"" + _oname + "\"";
                    }
                    else
                    {
                        ret += tb0 + "new Pyr.createElement(\r\n" + tb1 + "" + _oname + "";
                    }
                }
                else
                {
                    ret += tb0 + "new Pyr.createElement(\r\n" + tb1 + Name;
                }
                if (pou != "")
                {
                    ret += ",\r\n" + tb1 + "{ " + pou + " }, \r\n";
                }
                else
                {
                    ret += ",\r\n" + tb1 + "null, \r\n";
                }
                InnerComponent.ForEach(x => { ret += x.Compile(hm0, false) + ", \r\n"; });
                ret  = ret.Substring(0, ret.Length - 4);
                ret += "\r\n" + tb0 + ")";
            }
            else
            {
                var tb0 = DoTabs(iret ? 0 : tabs);

                if (_base.Contains(_oname) || _oname.ToLower() == _oname)
                {
                    ret += tb0 + "new Pyr.createElement(" + "\"" + _oname + "\"";
                }
                else
                {
                    var fncreate = assingBlock.SymbolTable.Get("constructor " + Name);
                    if (fncreate is Error)
                    {
                        _componentNotHaveConstructor = true;
                        if (assingBlock.SymbolTable.Get(Name) is Error)
                        {
                            _componentNotHaveConstructor = false;
                            _componentNotFound           = true;
                        }
                        return("");
                    }
                    else
                    {
                        var cls = assingBlock.SymbolTable.Get(Name);
                        if (cls is Class clss)
                        {
                            if (clss.GetParent()?.Name.Value != "Component")
                            {
                                _componentNotHaveParent = true;
                                return("");
                            }
                        }
                    }

                    if (fncreate is Function fa)
                    {
                        ret += tb0 + "new Pyr.createElement(" + Name + "." + fa.Name;
                    }
                    else
                    {
                        ret += tb0 + "new Pyr.createElement(" + Name;
                    }
                }
                if (pou != "")
                {
                    ret += ", { " + pou + " }, ";
                }
                else
                {
                    ret += ", null, ";
                }
                if (replace != "")
                {
                    ret += "\"" + replace + "\"";
                }
                else
                {
                    ret += "null";
                }
                ret += ")";
            }

            if (IsStart)
            {
                return("var _this = this;\r\n" + DoTabs(tabs + 1) + "return " + ret + ";");
            }
            if (iret)
            {
                return("return " + ret + ";");
            }
            return(ret);
        }
 /// <summary>
 /// Cleans button from text inside
 /// </summary>
 public void ClearInnerText()
 {
     InnerText.Clear();
 }