예제 #1
0
        public HtmlTag(string tag)
            : this()
        {
            tag = tag.Substring(1, tag.Length - 2);

            var spaceIndex = tag.IndexOf(" ");

            //Extract tag name
            if (spaceIndex < 0)
            {
                TagName = tag;
            }
            else
            {
                TagName = tag.Substring(0, spaceIndex);
            }

            //Check if is end tag
            if (TagName.StartsWith("/"))
            {
                IsClosing = true;
                TagName   = TagName.Substring(1);
            }

            TagName = TagName.ToLower();

            //Extract attributes
            var atts = Parser.Match(Parser.HmlTagAttributes, tag);

            foreach (Match att in atts)
            {
                //Extract attribute and value
                var chunks = att.Value.Split('=');

                if (chunks.Length == 1)
                {
                    if (!Attributes.ContainsKey(chunks[0]))
                    {
                        Attributes.Add(chunks[0].ToLower(), string.Empty);
                    }
                }
                else if (chunks.Length == 2)
                {
                    var attname  = chunks[0].Trim();
                    var attvalue = chunks[1].Trim();

                    if (attvalue.StartsWith("\"") && attvalue.EndsWith("\"") && attvalue.Length > 2)
                    {
                        attvalue = attvalue.Substring(1, attvalue.Length - 2);
                    }

                    if (!Attributes.ContainsKey(attname))
                    {
                        Attributes.Add(attname, attvalue);
                    }
                }
            }
        }
        private bool UpdateTags(Game game)
        {
            bool       IsUpdated = false;
            List <Tag> Tags      = game.Tags;

            if (Tags != null && Tags.Count > 0)
            {
                // Rename
                List <Tag> AllTagsOld = Tags.FindAll(x => PluginSettings.ListTagsEquivalences.Any(y => y.OldNames.Any(z => z.ToLower() == x.Name.ToLower())));

                if (AllTagsOld.Count > 0)
                {
                    // Remove all
                    foreach (Tag tag in AllTagsOld)
                    {
                        game.TagIds.Remove(tag.Id);
                        IsUpdated = true;
                    }

                    // Set all
                    foreach (LmTagsEquivalences item in PluginSettings.ListTagsEquivalences.FindAll(x => x.OldNames.Any(y => AllTagsOld.Any(z => z.Name.ToLower() == y.ToLower()))))
                    {
                        if (item.Id != null)
                        {
                            game.TagIds.AddMissing((Guid)item.Id);
                            IsUpdated = true;
                        }
                    }
                }

                // Exclusion
                if (PluginSettings.ListTagsExclusion.Count > 0)
                {
                    foreach (string TagName in PluginSettings.ListTagsExclusion)
                    {
                        Tag TagDelete = game.Tags.Find(x => x.Name.ToLower() == TagName.ToLower());
                        if (TagDelete != null)
                        {
                            game.TagIds.Remove(TagDelete.Id);
                            IsUpdated = true;
                        }
                    }
                }
            }

            if (IsUpdated)
            {
                Application.Current.Dispatcher?.BeginInvoke((Action) delegate
                {
                    PlayniteApi.Database.Games.Update(game);
                }).Wait();
            }

            return(IsUpdated);
        }
예제 #3
0
        private bool IsSelfClosing()
        {
            // Ref: http://www.w3.org/tr/html5/syntax.html
            // Section 8.1.2 (Void Elements)

            var targets = new string[] {
                "area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link",
                "meta", "param", "source", "track", "wbr"
            };

            return(targets.Contains(TagName.ToLower()));
        }
예제 #4
0
        /// <devdoc>
        /// <para>[To be supplied.]</para>
        /// </devdoc>
        protected override bool OnStyleAttributeRender(string name, string value, HtmlTextWriterStyle key)
        {
            if (_docType == XhtmlMobileDocType.XhtmlBasic)
            {
                return(false);
            }

            if (TagName.ToLower(CultureInfo.InvariantCulture).Equals("div") && name.ToLower(CultureInfo.InvariantCulture).Equals("border-collapse"))
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// creates a friendly (albeit silly) name for the element
        /// </summary>
        /// <returns></returns>
        private string GetFriendlyName()
        {
            var builder = new StringBuilder(TagName.ToLower());

            if (_attributes.Count > 0)
            {
                string findvalue = _attributes[0].FindValue;
                findvalue = Regex.Replace(findvalue, "[^a-z0-9_]", "", RegexOptions.IgnoreCase);
                int strLength = findvalue.Length > 15 ? 15 : findvalue.Length;
                builder.Append(UppercaseFirstLetter(findvalue.Substring(0, strLength)));
            }

            return(builder.ToString());
        }
예제 #6
0
        public string GetStringValue()
        {
            if (TagName.ToLower() == "input")
            {
                return(Attributes.GetValueOrDefault("value") ?? string.Empty);
            }

            if (TagName.ToLower() == "select")
            {
                return(string.Empty);
            }

            return(Text.Trim());
        }
예제 #7
0
 public override int GetHashCode()
 {
     return(TagName.ToLower().GetHashCode());
 }