css

package
v0.0.0-...-e7516ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package css extracts colours from HTML and CSS files.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CML

type CML struct {
	// URL where the colors are from
	URL      *url.URL
	Mentions []*ColorMention
}

CML ColorMention List

func ParsePage

func ParsePage(p *page.Page) (*CML, error)

ParsePage returns a CML containing all CSS colors.

type ColorMention

type ColorMention struct {
	Color *colorful.Color
	// color, background-color
	Property string
	// .class, nav > a
	// Selectors for inline CSS are based on Context structs.
	// Otherwise the typical CSS selector is used.
	Selector string
}

ColorMention is a single occurrence of a color in a certain context.

func New

func New(c *colorful.Color, property, selector string) *ColorMention

New ColorMention of a color for a property at a certain selector.

func ParseHTML

func ParseHTML(s string) ([]*ColorMention, error)

ParseHTML extract colors from "style" attributes and elements.

Example
cms, _ := ParseHTML(`<style>body{color:#001122}</style>
<div id="some-div" class="some-class">
	<span style="background-color:red"></span>
</div>
`)
for _, cm := range cms {
	fmt.Printf("%s %s = %s\n", cm.Selector, cm.Property, cm.Color.Hex())
}
Output:

body color = #001122
html > body > div#some-div.some-class > span background-color = #ff0000

func ParseStylesheet

func ParseStylesheet(sheet string) []*ColorMention

ParseStylesheet extracts colors from a full CSS stylesheet.

type Context

type Context []string

Context is a stack of selectors, like element names and class or id attributes. It describes the hierarchy in a HTML document.

func (*Context) Pop

func (c *Context) Pop() (string, error)

Pop a selector off the stack. Returns an error when the stack is empty.

func (*Context) Push

func (c *Context) Push(ctx string)

Push a selector on the stack.

func (Context) String

func (c Context) String() string

String representation of a Context stack.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL