Esempio n. 1
0
        private string ParseAtViewportRule(string css_text, List <AtRule> atrules, string browserPrefix)
        {
            int i = 0;
            var j = css_text.IndexOf("}", i);
            var viewportRule_Text        = css_text.Substring(i, (j - i + 1));
            var viewportRule             = new AtViewportRule(browserPrefix);
            var viewportRule_TrimmedText = viewportRule_Text.Substring(0, viewportRule_Text.Length - 1);

            List <string> declerations = viewportRule_TrimmedText.Split('{')[1].Split(';').ToList();

            foreach (string decleration_raw in declerations)
            {
                var decleration = decleration_raw.Trim();
                if (decleration != "")
                {
                    if (decleration.Contains("url") && decleration.Contains("(") && !decleration.Contains(")"))
                    {
                        decleration += ";" + declerations[i + 1];
                        declerations.Remove(declerations[i + 1]);
                        decleration = decleration.Trim();
                    }

                    string[] PropertyAndValue = decleration.Split(":".ToCharArray(), 2);
                    var      property         = new Property(PropertyAndValue[0].Trim());
                    var      value            = new Value(PropertyAndValue[1].Trim());
                    var      dec = new Decleration(property, value);
                    viewportRule.Declerations.Add(dec);
                }
            }
            atrules.Add(viewportRule);

            css_text = css_text.Replace(viewportRule_Text, "");
            i        = 0; j = 0;
            return(css_text);
        }
Esempio n. 2
0
        private string ParseAtPageRule(string css_text, List <AtRule> atrules)
        {
            int i                    = 0;
            var j                    = css_text.IndexOf("}", i);
            var pageRule_Text        = css_text.Substring(i, (j - i + 1));
            var pageRule             = new AtPageRule();
            var pageRule_TrimmedText = pageRule_Text.Substring(0, pageRule_Text.Length - 1);

            if (pageRule_TrimmedText.Split('{')[0].TrimEnd().Length > "@page".Length)
            {
                pageRule.PseudoClass = pageRule_TrimmedText.Split('{')[0].Substring("@page".Length).Trim();
            }
            else
            {
                pageRule.PseudoClass = "";
            }

            List <string> declerations = pageRule_TrimmedText.Split('{')[1].Split(';').ToList();

            foreach (string decleration_raw in declerations)
            {
                var decleration = decleration_raw.Trim();
                if (decleration != "")
                {
                    if (decleration.Contains("url") && decleration.Contains("(") && !decleration.Contains(")"))
                    {
                        decleration += ";" + declerations[i + 1];
                        declerations.Remove(declerations[i + 1]);
                        decleration = decleration.Trim();
                    }

                    string[] PropertyAndValue = decleration.Split(":".ToCharArray(), 2);
                    var      property         = new Property(PropertyAndValue[0].Trim());
                    var      value            = new Value(PropertyAndValue[1].Trim());
                    var      dec = new Decleration(property, value);
                    pageRule.Declerations.Add(dec);
                }
            }
            atrules.Add(pageRule);

            css_text = css_text.Replace(pageRule_Text, "");
            i        = 0; j = 0;
            return(css_text);
        }
Esempio n. 3
0
        private string ParseAtFont_FaceRule(string css_text, List <AtRule> atrules)
        {
            int i = 0;
            var j = css_text.IndexOf("}", i);
            var font_faceRule_Text = css_text.Substring(i, (j - i + 1));

            var           font_faceRule             = new AtFont_FaceRule();
            var           font_faceRule_TrimmedText = font_faceRule_Text.Substring(0, font_faceRule_Text.Length - 1);
            List <string> declerations = font_faceRule_TrimmedText.Split('{')[1].Split(';').ToList();

            for (i = 0; i < declerations.Count; i++)
            {
                var decleration = declerations[i].Trim();
                if (decleration != "")
                {
                    if (decleration.Contains("url"))
                    {
                        if (decleration.Count(c => c == '(') != decleration.Count(c => c == ')'))
                        {
                            decleration += ";" + declerations[i + 1];
                            i++;
                            decleration = decleration.Trim();
                        }
                    }
                    string[] PropertyAndValue = decleration.Split(":".ToCharArray(), 2);
                    var      property         = new Property(PropertyAndValue[0].Trim());
                    var      value            = new Value(PropertyAndValue[1].Trim());
                    var      dec = new Decleration(property, value);
                    font_faceRule.Declerations.Add(dec);
                }
            }
            atrules.Add(font_faceRule);


            css_text = css_text.Replace(font_faceRule_Text, "");
            i        = 0; j = 0;
            return(css_text);
        }
Esempio n. 4
0
 public void AddDecleration(Decleration dec)
 {
     declerations.Add(dec);
 }
Esempio n. 5
0
        private void ParseRuleSets(string css_text, List <Ruleset> rulesets)
        {
            string[] Rulesets = css_text.Split('}');
            foreach (string ruleset_raw in Rulesets)
            {
                var ruleset = ruleset_raw.Trim();
                if (ruleset != "")
                {
                    string[] SelectorsAndDeclerations = ruleset.Split('{');
                    if (SelectorsAndDeclerations[0].Contains(","))
                    {
                        string[]      selectors    = SelectorsAndDeclerations[0].Split(',');
                        List <string> declerations = SelectorsAndDeclerations[1].Split(';').ToList();
                        foreach (string selector in selectors)
                        {
                            if (selector != "")
                            {
                                var      rule  = new Ruleset();
                                Selector slctr = new Selector(selector.Trim());
                                rule.selector = slctr;
                                for (int i = 0; i < declerations.Count; i++)
                                {
                                    var decleration = declerations[i];
                                    if (decleration != "")
                                    {
                                        if (decleration.Contains("url") && decleration.Contains("(") && !decleration.Contains(")"))
                                        {
                                            decleration += ";" + declerations[i + 1];
                                            //declerations.Remove(declerations[i + 1]);
                                            i++;
                                            decleration = decleration.Trim();
                                        }

                                        string[] PropertyAndValue = decleration.Split(":".ToCharArray(), 2);
                                        var      property         = new Property(PropertyAndValue[0].Trim());
                                        var      value            = new Value(PropertyAndValue[1].Trim());
                                        var      dec = new Decleration(property, value);
                                        rule.AddDecleration(dec);
                                    }
                                }
                                rulesets.Add(rule);
                            }
                        }
                    }
                    else
                    {
                        var      rule  = new Ruleset();
                        Selector slctr = new Selector(SelectorsAndDeclerations[0].Trim());
                        rule.selector = slctr;
                        List <string> declerations = SelectorsAndDeclerations[1].Split(';').ToList();
                        for (int i = 0; i < declerations.Count; i++)
                        {
                            var decleration = declerations[i];
                            if (decleration != "")
                            {
                                if (decleration.Contains("url") && decleration.Contains("(") && !decleration.Contains(")"))
                                {
                                    decleration += ";" + declerations[i + 1];
                                    //declerations.Remove(declerations[i + 1]);
                                    i++;
                                    decleration = decleration.Trim();
                                }

                                string[] PropertyAndValue = decleration.Split(":".ToCharArray(), 2);
                                var      property         = new Property(PropertyAndValue[0].Trim());
                                var      value            = new Value(PropertyAndValue[1].Trim());
                                var      dec = new Decleration(property, value);
                                rule.AddDecleration(dec);
                            }
                        }
                        rulesets.Add(rule);
                    }
                }
            }
        }