{"id":28602782,"url":"https://github.com/tomashevskyi-vladyslav/parser_for_css_and_html","last_synced_at":"2026-04-02T02:07:15.791Z","repository":{"id":297631705,"uuid":"806583317","full_name":"Tomashevskyi-Vladyslav/Parser_for_CSS_and_HTML","owner":"Tomashevskyi-Vladyslav","description":"CSSParser is a C++ CSS parser and selector that can read complete CSS stylesheets or individual CSS lines and map the rules to a custom node tree provided by the implementing library/application.","archived":false,"fork":false,"pushed_at":"2025-06-06T14:07:45.000Z","size":344,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T14:35:47.927Z","etag":null,"topics":["c-plus-plus","cpp","css-parser","development","library"],"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/Tomashevskyi-Vladyslav.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2024-05-27T13:27:08.000Z","updated_at":"2025-06-06T14:07:47.000Z","dependencies_parsed_at":"2025-06-06T14:46:01.185Z","dependency_job_id":null,"html_url":"https://github.com/Tomashevskyi-Vladyslav/Parser_for_CSS_and_HTML","commit_stats":null,"previous_names":["tomashevskyi-vladyslav/parser_for_css_and_html"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Tomashevskyi-Vladyslav/Parser_for_CSS_and_HTML","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomashevskyi-Vladyslav%2FParser_for_CSS_and_HTML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomashevskyi-Vladyslav%2FParser_for_CSS_and_HTML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomashevskyi-Vladyslav%2FParser_for_CSS_and_HTML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomashevskyi-Vladyslav%2FParser_for_CSS_and_HTML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tomashevskyi-Vladyslav","download_url":"https://codeload.github.com/Tomashevskyi-Vladyslav/Parser_for_CSS_and_HTML/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tomashevskyi-Vladyslav%2FParser_for_CSS_and_HTML/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31294398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:43:37.129Z","status":"online","status_checked_at":"2026-04-02T02:00:08.535Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-plus-plus","cpp","css-parser","development","library"],"created_at":"2025-06-11T16:08:26.402Z","updated_at":"2026-04-02T02:07:15.760Z","avatar_url":"https://github.com/Tomashevskyi-Vladyslav.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parser_for_CSS_and_HTML\n\nA C++ CSS Parser\n\n[![LISCENSE](https://img.shields.io/packagist/l/doctrine/orm.svg)](./LICENSE.md)\n\n### This is a fork of luojilab´s [DDCSSParser](https://github.com/luojilab/CSSParser \"DDCSSParser\").\u003cbr\u003eFull credits goes to Tomashevskyi-Vladyslav for writing the CSS Parser and Gumbo code.\n------\n\nCSSParser++ is a C++ CSS parser and selector, that can read full CSS stylesheets or standalone CSS strings and match the rules with a custom node tree provided by the \nimplementing library/application.\n\nPlease check the CustomNodeExample project for a full example.\n\n## Changes from DDCSSParser\n\n- Project has been converted to a Visual Studio solution\n- Code has been split into 3 Visual Studio projects \n  - A CSSParser library - this outputs a lib file that can be used by implementing libraries/applications\n  - A CustomNodeExample console application - Example that showcases how to provide a custom node class to the CSSParser and retrieve the matching style rules for each node\n  - A GumboExample console application - the original example from DDCSSParser\n- The CSSParser library is no longer dependent on Gumbo\n- A new API based on the INodeSelector interface has been added, allowing implementing libraries/applications to provide their own custom node tree to the node-selector resolvers.\n- Various minor changes and fixes\n\n\n## Installation\n\n##### Using the Code\n\n* Clone the source code into a working directory `git clone https://github.com/Tomashevskyi-Vladyslav/Parser_for_CSS_and_HTML.git`\n* Open the Visual Studio solution\n* Build the CSSParser library (in Release mode)\n* Link the compiled cssparser.lib in your project, and add the \"CssParser\\include\" directory to your include path. \n\n##### Running the example Apps\n\n* Open the Visual Studio solution\n* Build All\n* Run either the CustomNodeExample or the GumboExample\n\n## Features\n\n* Parse CSS files or strings\n* Easily iterate through the CSS selectors and rules\n* CSS rules is provided as raw string or std::map key/value pairs\n* Use INodeSelector interface to match a custom node tree automatically\nwith the CSS selectors. \n\n#### Supported CSS Selectors:\n\n- Simple Selector:\n  - Type Selector\n  - Universal Selector\n  - Attribute Selector\n  - Class Selector\n  - ID Selector\n  - Pseudo Class\n- Selector Sequence\n- Selector Group\n- Combinators:\n  - Descendant combinator\n  - Child combinators\n  - Sibling combinators\n\n\n## Basic Usage\n\n* Parse CSS files or strings\n\n  ```c++\n  // Parse CSS file\n  future::CSSParser* parser = new future::CSSParser();\n  parser-\u003eparseByFile(\"/Path/to/CssFile\");\n  std::vector\u003cfuture::Selector *\u003eselectors = parser\u003egetSelectors();\n  \n  // Parse CSS string\n  parser-\u003eparseByString(\"body #id { color: black; }\");\n  std::vector\u003cfuture::Selector *\u003eselectors = parser\u003egetSelectors();\n  ```\n\n* Print all selector descriptions and rules\n\n  ```c++\n  int i = 1;\n  printf(\"\\n\\n********** All Selectors **********\\n\\n\");\n  for (future::Selector* s : selectors) {\n      printf(\"#%i\\n\\n\", i++);\n      printf(\"%s\\n\\n\", s-\u003edescription().c_str());\n      printf(\"specificity: %i\\n\\n\\n\", s-\u003eweight());\n\n      auto ruleMap = s-\u003egetRuleDataMap();\n      for (const auto\u0026 rule : ruleMap) {\n          printf(\"%s: %s\\n\", rule.first.c_str(), rule.second.c_str());\n      }\n\n      printf(\"\\n----------------------\\n\\n\");\n  }\n  printf(\"\\n\");\n  ```\n\n* Match custom node with selector and handle selector rules and specificity if the node macthes a selector (See the CustomNodeExample for the full code)\n\n  ```c++\n  int selIdx = 1;\n  CustomNode* node = new CustomNode(); // \u003c-- Your custom node \n  for (future::Selector* s : selectors) {\n      if (future::NodeSelectorResolver::DoesNodeMatchSelector(node, s)) {\n          auto spec = s-\u003eweight();\n          auto ruleMap = s-\u003egetRuleDataMap();\n\n          ApplyStyleRules(node, ruleMap, spec);\n\n          printf(\"node %s%s %s matched with selector #%i\\n\", \n          node-\u003etag.c_str(), node-\u003eGetIdDesc().c_str(), node-\u003eGetClassesDesc().c_str(), selIdx);\n      }\n      selIdx++;\n  }\n  ```\n\n## Applicability\n\nThe code has been tested on Windows\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomashevskyi-vladyslav%2Fparser_for_css_and_html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomashevskyi-vladyslav%2Fparser_for_css_and_html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomashevskyi-vladyslav%2Fparser_for_css_and_html/lists"}