Exemple #1
0
 public static void AddAttribute(HtmlAttributeCollection atributos, string key, string value, FieldTypes fieldType)
 {
     if (atributos.Contains(key))
     {
         atributos[key].Value += ", " + value;
     }
     else
     {
         atributos.Add(key, value);
     }
 }
Exemple #2
0
 /// <summary>
 /// Gets the value of an HTML attribute safely from an HTMLAttributeCollection
 /// </summary>
 /// <param name="p_hacCollection"></param>
 /// <param name="p_strItem"></param>
 /// <returns></returns>
 private static string GetHtmlAttributeValue(HtmlAttributeCollection p_hacCollection, string p_strItem)
 {
     if (p_hacCollection.Contains(p_strItem))
     {
         return(((HtmlAttribute)p_hacCollection[p_strItem]).Value);
     }
     else
     {
         return("");
     }
 }
Exemple #3
0
 public static void AppendOrCreate(this HtmlAttributeCollection helper, string name, string value)
 {
     if (!helper.Contains(name))
     {
         helper.Append(name, value);
     }
     else
     {
         helper[name].Value += value;
     }
 }
        protected bool isAttributeValueEquals(HtmlAttributeCollection attributes, string attr, string str)
        {
            try
            {
                if (attributes.Contains(attr))
                {
                    if (attributes[attr].Value == str)
                    {
                        return(true);
                    }
                }
            } catch (Exception) { }

            return(false);
        }
Exemple #5
0
        private IEnumerable <TokenBase> ParseNodes(HtmlNode container, Stack <TextVisualProperties> propertiesStack, TokenIndex top, EpubPath path, int parentID = -1)
        {
            foreach (HtmlNode child in container.ChildNodes)
            {
                var asText = child as HtmlTextNode;
                if (asText != null && !string.IsNullOrEmpty(asText.Text))
                {
                    foreach (TokenBase text in ParseText(asText.Text, top))
                    {
                        yield return(text);
                    }
                }
                else
                {
                    TextVisualProperties properties = propertiesStack.Peek().Clone().Update(child, _css);
                    properties.LinkID = string.Empty;

                    if (child.Name == "a" || child.Name == "span")
                    {
                        ParseAnchors(top, path, child);
                    }

                    if (child.Name == "a")
                    {
                        string href = child.GetAttributeValue("href", string.Empty);
                        if (!string.IsNullOrEmpty(href))
                        {
                            if (href.StartsWith("#"))
                            {
                                properties.LinkID = path.CurrentFilePath + href;
                            }
                            else
                            {
                                properties.LinkID = path + href;
                            }
                        }
                    }
                    if (string.Equals(child.Name, "img"))
                    {
                        HtmlAttributeCollection attributes = child.Attributes;
                        string src          = attributes.Contains("src") ? attributes["src"].Value : string.Empty;
                        var    pictureToken = new PictureToken(top.Index++, (path) + src);
                        yield return(pictureToken);
                    }
                    else
                    {
                        if (child is HtmlCommentNode)
                        {
                            continue;
                        }

                        var tagOpenToken = new TagOpenToken(top.Index++, child, properties, parentID);
                        yield return(tagOpenToken);

                        propertiesStack.Push(properties);
                        foreach (TokenBase token in ParseNodes(child, propertiesStack, top, path, tagOpenToken.ID))
                        {
                            yield return(token);
                        }
                        propertiesStack.Pop();
                        yield return(new TagCloseToken(top.Index++, parentID));
                    }
                }
            }
        }
 /// <summary>
 /// Checks for existence of attribute with given name
 /// </summary>
 public bool Contains(string Name)
 {
     return(attributes.Contains(Name));
 }
        protected virtual void SetAttributes(XElement element, HtmlNode htmlNode, ParseDefinition definition)
        {
            List <ParseAttribute>   applicableAttributes = definition.FindApplicableAttributes(htmlNode);
            HtmlAttributeCollection attributes           = htmlNode.Attributes;

            foreach (ParseAttribute parseAttribute in applicableAttributes)
            {
                try
                {
                    if (!string.IsNullOrEmpty(parseAttribute.XmlAttribute))
                    {
                        string attributeValue = string.Empty;
                        if (!string.IsNullOrEmpty(parseAttribute.HtmlAttribute) && attributes != null && attributes.Contains(parseAttribute.HtmlAttribute))
                        {
                            attributeValue = attributes[parseAttribute.HtmlAttribute].Value;
                            if (attributeValue.Equals(parseAttribute.HtmlDefaultValue))
                            {
                                attributeValue = parseAttribute.XmlDefaultValue;
                            }
                            else if (parseAttribute.HtmlAttribute.Equals("width", StringComparison.InvariantCultureIgnoreCase) || parseAttribute.HtmlAttribute.Equals("height", StringComparison.InvariantCultureIgnoreCase))
                            {
                                attributeValue = HtmlParseHelper.ParseDimensionValue(attributeValue, true);
                            }
                        }
                        if (string.IsNullOrEmpty(attributeValue))
                        {
                            attributeValue = parseAttribute.XmlDefaultValue;
                        }
                        element.SetAttributeValue((XName)parseAttribute.XmlAttribute, (object)attributeValue);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("ParseAttributes", ex);
                }
            }
        }