{"id":19189316,"url":"https://github.com/visualon/cssparser","last_synced_at":"2025-07-04T19:36:21.120Z","repository":{"id":43332634,"uuid":"160486736","full_name":"visualon/cssparser","owner":"visualon","description":"CSS Parser for .NET","archived":false,"fork":false,"pushed_at":"2025-04-14T23:15:09.000Z","size":688,"stargazers_count":7,"open_issues_count":6,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-08T03:07:35.051Z","etag":null,"topics":["csharp","css","dotnet"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/visualon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-05T08:38:38.000Z","updated_at":"2025-03-05T13:51:07.000Z","dependencies_parsed_at":"2023-02-08T16:31:31.394Z","dependency_job_id":"1f25e64f-dc58-48f2-90a6-90bbe9c2a3b0","html_url":"https://github.com/visualon/cssparser","commit_stats":{"total_commits":169,"total_committers":7,"mean_commits":"24.142857142857142","dds":0.6686390532544378,"last_synced_commit":"c6b87c9958ac4add0a4cf1ab0d4359f409a7265f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualon%2Fcssparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualon%2Fcssparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualon%2Fcssparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualon%2Fcssparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/visualon","download_url":"https://codeload.github.com/visualon/cssparser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252989951,"owners_count":21836667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","css","dotnet"],"created_at":"2024-11-09T11:29:00.729Z","updated_at":"2025-05-08T03:07:42.259Z","avatar_url":"https://github.com/visualon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSS Parser\r\n\r\n[![build](https://github.com/visualon/cssparser/actions/workflows/build.yml/badge.svg)](https://github.com/visualon/cssparser/actions/workflows/build.yml)\r\n[![VisualOn.CSSParser](https://img.shields.io/nuget/v/VisualOn.CSSParser?label=VisualOn.CSSParser)](https://www.nuget.org/packages/VisualOn.CssParser)\r\n[![VisualOn.CSSParser.ExtendedLESSParser](https://img.shields.io/nuget/v/VisualOn.CSSParser.ExtendedLESSParser?label=VisualOn.CSSParser.ExtendedLESSParser)](https://www.nuget.org/packages/VisualOn.CssParser.ExtendedLESSParser)\r\n[![codecov](https://codecov.io/gh/visualon/cssparser/branch/main/graph/badge.svg?token=EEGfq3zpqS)](https://codecov.io/gh/visualon/cssparser)\r\n![LICENSE](https://img.shields.io/github/license/visualon/cssparser)\r\n\r\nThis is a fork from [Dan Roberts](https://bitbucket.org/DanRoberts/cssparser).\r\n\r\nA simple CSS and LESS parser to categorise strings of content and optionally generate a hierarchical representation of it.\r\n\r\n## Changes\r\n\r\nSee [Releases](https://github.com/visualon/cssparser/releases)\r\n\r\n## License\r\n\r\n[MIT License](LICENSE.txt)\r\n\r\n### Howto\r\n\r\nThis was written to fulfill a need I had to run quickly through a string of CSS and identify what \"type\" each character was. With an optional ability to parse it into hierarchical data describing nested selectors and/or media queries (most applicable to LESS rather than vanilla CSS since LESS supports nesting of selectors whereas CSS only supports single nesting of a selector within a media query).\r\n\r\n    IEnumerable\u003cCategorisedCharacterString\u003e ParseCSS(string content)\r\n\r\nand\r\n\r\n    IEnumerable\u003cCategorisedCharacterString\u003e ParseLESS(string content)\r\n\r\n(within the static class **CSSParser.Parser**) do the basic parsing work where **CategorisedCharacterString** has the properties\r\n\r\n    public class CategorisedCharacterString\r\n    {\r\n      /// \u003csummary\u003e\r\n      /// This will never be null or an empty string\r\n      /// \u003c/summary\u003e\r\n      public string Value { get; }\r\n\r\n      /// \u003csummary\u003e\r\n      /// This is the location of the start of the string in the source data\r\n      /// \u003c/summary\u003e\r\n      public int IndexInSource { get; }\r\n\r\n      public CharacterCategorisationOptions CharacterCategorisation { get; }\r\n    }\r\n\r\n    public enum CharacterCategorisationOptions\r\n    {\r\n      Comment,\r\n      CloseBrace,\r\n      OpenBrace,\r\n      SemiColon,\r\n      SelectorOrStyleProperty,\r\n      StylePropertyColon,\r\n      Value,\r\n      Whitespace\r\n    }\r\n\r\nso calling ParseCSS on\r\n\r\n    /* Test */ .Content { color: black; }\r\n\r\nwill return **CategorisedCharacterString** instances with the data\r\n\r\n    \"/* Test */\"     Comment (IndexInSource 0)\r\n    \" \"              Whitespace (IndexInSource 10)\r\n    \".Content\"       SelectorOrStyleProperty (IndexInSource 11)\r\n    \" \"              Whitespace (IndexInSource 19)\r\n    \"{\"              OpenBrace (IndexInSource 20)\r\n    \" \"              Whitespace (IndexInSource 19)\r\n    \"color\"          SelectorOrStyleProperty (IndexInSource 22)\r\n    \":\"              StylePropertyColon (IndexInSource 27)\r\n    \" \"              Whitespace (IndexInSource 28)\r\n    \"black\"          Value (IndexInSource 29)\r\n    \";\"              SemiColon (IndexInSource 34)\r\n    \" \"              Whitespace (IndexInSource 35)\r\n    \"}\"              CloseBrace (IndexInSource 36)\r\n\r\nThis analysis can be done very cheaply as it is only a very simple representation. It does not, for example, differentiate between the type of the \".Content\" value or \"color\", they are both considered to be of type **SelectorOrStyleProperty**.\r\n\r\nTo arrange in a hierchical manner and to categorise more strictly, the data return from ParseCSS or ParseLess can be passed into\r\n\r\n    IEnumerable\u003cICSSFragment\u003e ParseIntoStructuredData(\r\n      IEnumerable\u003cCategorisedCharacterString\u003e segments\r\n    )\r\n\r\n(within the static class **CSSParser.ExtendedLESSParser.LessCssHierarchicalParser**) which transforms the data again. The interface **ICSSFragment** is implemented by the classes **Import** (describing an import statement for another stylesheet), a **MediaQuery** or a **Selector** (both of which have a \"ChildFragments\" set as they may contain other media queries, selectors and/or properties), a **StylePropertyName** or **StylePropertyValue**. Note that comments and whitespace are not included in this data.\r\n\r\nSo content such as\r\n\r\n    // Example\r\n    html\r\n    {\r\n      h1\r\n      {\r\n        color: black;\r\n        background: white url(\"background.jpg\") no-repeat top left;\r\n      }\r\n      p.Intro { padding: 8px; }\r\n    }\r\n\r\nbecomes something like\r\n\r\n    html\r\n      h1\r\n        color\r\n          black\r\n        background\r\n          white\r\n          url(\"background.jpg\")\r\n          no-repat\r\n          top\r\n          left\r\n      p.Intro\r\n        padding\r\n          8px\r\n\r\n_(Above: \"html\" represent a Selector instance with a ChildFragments property containing Selector instances for the \"h1\" and \"p\", each with ChildFragments data made up of StylePropertyValue and StylePropertyValue instances)._\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvisualon%2Fcssparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvisualon%2Fcssparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvisualon%2Fcssparser/lists"}