Skip to content

grapoza/DotNetCSS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DotNetCSS StyleSheet Parser for .NET

Build status NuGet

Overview

DotNetCSS is a continuation of the ExCSS CSS parser project. The orignal project appears to no longer take pull requests, and so this project was created to pick up where ExCSS version 3.0 left off. DotNetCSS is a .NET implementation of a CSS 2.1 and CSS 3 lexer and parser intended to provide an easy-to-use CSS object model.

Installation

DotNetCSS can be installed from the Visual Studio NuGet Package Manager, or from the NuGet Package Manager Console:

Install-Package DotNetCSS

Or, use your favorite package management tool (.NET CLI, Paket CLI, etc).

A basic example

using DotNetCSS;
using System;
using System.Linq;

namespace SampleDotNetCSS
{
    class Program
    {
        static void Main(string[] args)
        {
            var parser = new StylesheetParser();
            var stylesheet = parser.Parse(".someClass{color: red; background-image: url('/images/logo.png')");
            var rule = stylesheet.StyleRules.First();

            Console.WriteLine($"Selector is {rule.Selector.Text}"); // Selector is .someClass
            Console.WriteLine($"Color is {rule.Style.Color}"); // Color is rgb(255, 0, 0)
            Console.WriteLine($"BackgroundImage is {rule.Style.BackgroundImage}"); // BackgroundImage is url('/images/logo.png')

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();
        }
    }
}

About

A CSS Parser for .NET

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages