Пример #1
0
        /// <summary>
        /// Read styles defined inside the dom structure in links and style elements.<br/>
        /// If the html tag is "style" tag parse it content and add to the css data for all future tags parsing.<br/>
        /// If the html tag is "link" that point to style data parse it content and add to the css data for all future tags parsing.<br/>
        /// </summary>
        /// <param name="box">the box to parse style data in</param>
        /// <param name="htmlContainer">the html container to use for reference resolve</param>
        /// <param name="cssData">the style data to fill with found styles</param>
        /// <param name="cssDataChanged">check if the css data has been modified by the handled html not to change the base css data</param>
        private void CascadeParseStyles(CssBox box, HtmlContainerInt htmlContainer, ref CssData cssData, ref bool cssDataChanged)
        {
            if (box.HtmlTag != null)
            {
                // Check for the <link rel=stylesheet> tag
                if (box.HtmlTag.Name.Equals("link", StringComparison.CurrentCultureIgnoreCase) &&
                    box.GetAttribute("rel", string.Empty).Equals("stylesheet", StringComparison.CurrentCultureIgnoreCase))
                {
                    CloneCssData(ref cssData, ref cssDataChanged);
                    string  stylesheet;
                    CssData stylesheetData;
                    StylesheetLoadHandler.LoadStylesheet(htmlContainer, box.GetAttribute("href", string.Empty), box.HtmlTag.Attributes, out stylesheet, out stylesheetData);
                    if (stylesheet != null)
                    {
                        _cssParser.ParseStyleSheet(cssData, stylesheet);
                    }
                    else if (stylesheetData != null)
                    {
                        cssData.Combine(stylesheetData);
                    }
                }

                // Check for the <style> tag
                if (box.HtmlTag.Name.Equals("style", StringComparison.CurrentCultureIgnoreCase) && box.Boxes.Count > 0)
                {
                    CloneCssData(ref cssData, ref cssDataChanged);
                    foreach (var child in box.Boxes)
                    {
                        _cssParser.ParseStyleSheet(cssData, child.Text.CutSubstring());
                    }
                }
            }

            foreach (var childBox in box.Boxes)
            {
                CascadeParseStyles(childBox, htmlContainer, ref cssData, ref cssDataChanged);
            }
        }
Пример #2
0
        /// <summary>
        /// Read styles defined inside the dom structure in links and style elements.<br/>
        /// If the html tag is "style" tag parse it content and add to the css data for all future tags parsing.<br/>
        /// If the html tag is "link" that point to style data parse it content and add to the css data for all future tags parsing.<br/>
        /// </summary>
        /// <param name="box">the box to parse style data in</param>
        /// <param name="htmlContainer">the html container to use for reference resolve</param>
        /// <param name="cssData">the style data to fill with found styles</param>
        /// <param name="cssDataChanged">check if the css data has been modified by the handled html not to change the base css data</param>
        private void CascadeParseStyles(CssBox box, HtmlContainerInt htmlContainer, CssDataWithChanged cssData)
        {
            if (box.HtmlTag != null)
            {
                // Check for the <link rel=stylesheet> tag
                if (box.HtmlTag.Name.Equals("link", StringComparison.CurrentCultureIgnoreCase) &&
                    box.GetAttribute("rel", string.Empty).Equals("stylesheet", StringComparison.CurrentCultureIgnoreCase))
                {
                    cssData.CloneCssData();

                    var stylesheetData = htmlContainer.ResourceServer.GetCssData(box.GetAttribute("href", string.Empty), box.HtmlTag.Attributes);

                    /*
                     * string stylesheet;
                     * CssData stylesheetData;
                     * StylesheetLoadHandler.LoadStylesheet(htmlContainer,
                     *  box.GetAttribute("href", string.Empty),
                     *  box.HtmlTag.Attributes, out stylesheet, out stylesheetData);
                     */
                    /*
                     * if (stylesheet != null)
                     *  _cssParser.ParseStyleSheet(cssData, stylesheet);
                     * else */
                    if (stylesheetData != null)
                    {
                        cssData.cssData.Combine(stylesheetData);
                    }
                }

                // Check for the <style> tag
                if (box.HtmlTag.Name.Equals("style", StringComparison.CurrentCultureIgnoreCase) && box.Boxes.Count > 0)
                {
                    cssData.CloneCssData();
                    foreach (var child in box.Boxes)
                    {
                        _cssParser.ParseStyleSheet(cssData.cssData, child.Text.CutSubstring());
                    }
                }
            }

            foreach (var childBox in box.Boxes)
            {
                CascadeParseStyles(childBox, htmlContainer, cssData);
            }
        }
Пример #3
0
 /// <summary>
 /// Parse the given stylesheet to <see cref="CssData"/> object.<br/>
 /// If <paramref name="combineWithDefault"/> is true the parsed css blocks are added to the 
 /// default css data (as defined by W3), merged if class name already exists. If false only the data in the given stylesheet is returned.
 /// </summary>
 /// <seealso cref="http://www.w3.org/TR/CSS21/sample.html"/>
 /// <param name="adapter">Platform adapter</param>
 /// <param name="stylesheet">the stylesheet source to parse</param>
 /// <param name="combineWithDefault">true - combine the parsed css data with default css data, false - return only the parsed css data</param>
 /// <returns>the parsed css data</returns>
 public static CssData Parse(RAdapter adapter, string stylesheet, bool combineWithDefault = true)
 {
     CssParser parser = new CssParser(adapter);
     return parser.ParseStyleSheet(stylesheet, combineWithDefault);
 }