You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/m2omou/parser-css

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/m2omou/parser-css

v0.0.0-20140507033957-703ac22e4e0c
Source
Go
Version published
Created
Source

Gocss

Gocss is a simple css parser written in GO, that provides a way to parse css selectors and properties.

Installation

$>go get github.com/m2omou/parser-css/src
import "github.com/m2omou/parser-css/src"

Code examples

####Type:####

The different type of selector, 'All' stand for the '*' css selector

const ( 
	Class = 1
	Id
	All
	Element
	Attribute
)

####Property:####

e.g: "color: white;"

type property struct {
        Name string 		// color
        Value string 		// white
}

####Selector:####

e.g ".container { color: white, float: left }"

type selector struct {
        Name string             // '.container'
        Properties []property   // [ { Name : 'color', Value : 'white' }, { Name : 'float', Value : 'left'} ]
        Type int                // Class
}

fd, err := os.Open("./style.css")
    
if err != nil {
        panic(err)
}
        
css := parserCSS(fd)
for s := range selectors {
        fmt.Println(selectors[s].Name)
        for p := range selectors[s].Properties {
                fmt.Println(selectors[s].Properties[p].Name + selectors[s].Properties[p].Value)
        }
}

For example this css :

body {
    width: 100%;
    height: 100%;
    Background: red;
}

.container {
    margin-bottom: 20px;
    height: 220px;
    width:300px;
    font-size: 14px;
}

Will return the following slice :

[
   {
      "Name":"body",
      "Properties":[
         {
            "Name":"width",
            "Value":"100%"
         },
         {
            "Name":"height",
            "Value":"100%"
         },
         {
            "Name":"Background",
            "Value":"red"
         }
      ],
      "Type":1
   },
   {
      "Name":".container",
      "Properties":[
         {
            "Name":"margin-bottom",
            "Value":"20px"
         },
         {
            "Name":"height",
            "Value":"220px"
         },
         {
            "Name":"width",
            "Value":"300px"
         },
         {
            "Name":"font-size",
            "Value":"14px"
         }
      ],
      "Type":1
   }
]

License

GOCSS Parser Copyright 2014 Mourad Sabour, mourad.sabour[at]gmail.com.

FAQs

Package last updated on 07 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts