Giter VIP home page Giter VIP logo

simple-css-parser's Introduction

OSBCP CSS Parser

A simple CSS parser in Java.

An oh, it is also very strict. If it finds an unexpected character in your CSS it self-destructs, taking you with you - making it a great tool to validate strict CSS.

Code examples

As String directly:

	List<Rule> rules = CSSParser.parse("div { width: 100px; -mozilla-opacity: 345; }");

Or from a file (using Apache Commons IO):

		String contents = IOUtils.toString(this.getClass().getResourceAsStream("stylesheet.css"));

		List<Rule> rules = CSSParser.parse(contents);

To print it all out:

	for (Rule rule : rules) {
	
		System.out.println(rule);
		
	}

Or go into details:

	for (Rule rule : rules) {
	
		// Get all the selectors (such as 'table', 'table td', 'a')
		List<Selector> selectors = rule.getSelectors();
		
		// Get all the property (such as 'width') and its value (such as '100px')	
		List<PropertyValue> propertyValues = rule.getPropertyValues();
	
	}

Please view the JavaDoc for more informaton.

Download

Download the latest version here:

https://github.com/corgrath/osbcp-css-parser/downloads/

JavaDoc

http://dl.dropbox.com/u/8183146/persistent/projects/java_osbcp_css_parser/javadoc/index.html

Reporting bugs

Please create an issue here:

https://github.com/corgrath/osbcp-css-parser/issues

Test coverage

Version 1.2

Code coverage

Code is also checked with PMD and Checkstyle.

Changes

v1.5 2012-04-28 Christoffer Pettersson

  • The parser can now handle nested comments. Thanks to Justin Marsan (HammHetfield) for reporting the bug.

v1.4 2012-03-11 Christoffer Pettersson

  • The parser now gives an error if it founds another colon : while reading the value.

v1.3 2012-02-08 Christoffer Pettersson

  • It is now possible to have duplicate property names in a rule

v1.2 2012-06-07 Christoffer Pettersson

  • Added IncorrectFormatException.ErrorCode for more specific exceptions
  • Added support for values with data URIs

v1.1 2012-02-06 Christoffer Pettersson

  • While inside the INSIDE_PROPERTY_NAME and a colon : is read, a IncorrectFormatException is thrown

v1.0 2012-02-05 Christoffer Pettersson

  • Initial release

License

OSBCP CSS Parser Copyright 2012 Christoffer Pettersson, christoffer[at]christoffer.me.

Licensed under the Apache License, Version 2.0

simple-css-parser's People

Contributors

corgrath avatar philippwiesemann avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.