Documentation ¶
Overview ¶
Package css is a CSS3 lexer and parser following the specifications at http://www.w3.org/TR/css-syntax-3/.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HSL2RGB ¶
HSL2RGB converts HSL to RGB with all of range [0,1] from http://www.w3.org/TR/css3-color/#hsl-color
func IsURLUnquoted ¶
IsURLUnquoted returns true if the bytes are a valid unquoted URL.
Types ¶
type GrammarType ¶
type GrammarType uint32
GrammarType determines the type of grammar.
const ( ErrorGrammar GrammarType = iota // extra token when errors occur CommentGrammar AtRuleGrammar BeginAtRuleGrammar EndAtRuleGrammar QualifiedRuleGrammar BeginRulesetGrammar EndRulesetGrammar DeclarationGrammar TokenGrammar CustomPropertyGrammar )
GrammarType values.
func (GrammarType) String ¶
func (tt GrammarType) String() string
String returns the string representation of a GrammarType.
type Hash ¶
type Hash uint32
Hash defines perfect hashes for a predefined list of strings
const ( Ms_Filter Hash = 0xa // -ms-filter Accelerator Hash = 0x49a0b // accelerator Aliceblue Hash = 0x59809 // aliceblue Alpha Hash = 0x62d05 // alpha Antiquewhite Hash = 0x4770c // antiquewhite Aquamarine Hash = 0x79e0a // aquamarine Azimuth Hash = 0x63107 // azimuth Background Hash = 0x2d0a // background Background_Attachment Hash = 0x4e215 // background-attachment Background_Color Hash = 0x17c10 // background-color Background_Image Hash = 0x60c10 // background-image Background_Position Hash = 0x2d13 // background-position Background_Position_X Hash = 0x8a315 // background-position-x Background_Position_Y Hash = 0x2d15 // background-position-y Background_Repeat Hash = 0x4211 // background-repeat Background_Size Hash = 0x660f // background-size Behavior Hash = 0x7508 // behavior Black Hash = 0xa505 // black Blanchedalmond Hash = 0xaa0e // blanchedalmond Blueviolet Hash = 0x59d0a // blueviolet Bold Hash = 0xbf04 // bold Border Hash = 0xca06 // border Border_Bottom Hash = 0xca0d // border-bottom Border_Bottom_Color Hash = 0xca13 // border-bottom-color Border_Bottom_Style Hash = 0xe913 // border-bottom-style Border_Bottom_Width Hash = 0x11013 // border-bottom-width Border_Box Hash = 0x1310a // border-box Border_Collapse Hash = 0x1620f // border-collapse Border_Color Hash = 0x18c0c // border-color Border_Left Hash = 0x1980b // border-left Border_Left_Color Hash = 0x19811 // border-left-color Border_Left_Style Hash = 0x1a911 // border-left-style Border_Left_Width Hash = 0x1ba11 // border-left-width Border_Right Hash = 0x1cb0c // border-right Border_Right_Color Hash = 0x1cb12 // border-right-color Border_Right_Style Hash = 0x1dd12 // border-right-style Border_Right_Width Hash = 0x1ef12 // border-right-width Border_Spacing Hash = 0x2010e // border-spacing Border_Style Hash = 0x20f0c // border-style Border_Top Hash = 0x21b0a // border-top Border_Top_Color Hash = 0x21b10 // border-top-color Border_Top_Style Hash = 0x22b10 // border-top-style Border_Top_Width Hash = 0x23b10 // border-top-width Border_Width Hash = 0x24b0c // border-width Bottom Hash = 0xd106 // bottom Box_Shadow Hash = 0x1380a // box-shadow Burlywood Hash = 0x25709 // burlywood Cadetblue Hash = 0x74c09 // cadetblue Calc Hash = 0x74904 // calc Caption_Side Hash = 0x2730c // caption-side Caret_Color Hash = 0x2850b // caret-color Center Hash = 0x10a06 // center Charset Hash = 0x45d07 // charset Chartreuse Hash = 0x2900a // chartreuse Chocolate Hash = 0x29a09 // chocolate Clear Hash = 0x2c805 // clear Clip Hash = 0x2cd04 // clip Color Hash = 0xd805 // color Column_Rule Hash = 0x3220b // column-rule Column_Rule_Color Hash = 0x32211 // column-rule-color Content Hash = 0x33307 // content Cornflowerblue Hash = 0x3430e // cornflowerblue Cornsilk Hash = 0x35108 // cornsilk Counter_Increment Hash = 0x35911 // counter-increment Counter_Reset Hash = 0x3740d // counter-reset Cue Hash = 0x38103 // cue Cue_After Hash = 0x38109 // cue-after Cue_Before Hash = 0x38a0a // cue-before Currentcolor Hash = 0x39b0c // currentcolor Cursive Hash = 0x3a707 // cursive Cursor Hash = 0x3ae06 // cursor Darkblue Hash = 0xb708 // darkblue Darkcyan Hash = 0xc208 // darkcyan Darkgoldenrod Hash = 0x25f0d // darkgoldenrod Darkgray Hash = 0x26b08 // darkgray Darkgreen Hash = 0x82e09 // darkgreen Darkkhaki Hash = 0x94509 // darkkhaki Darkmagenta Hash = 0x5600b // darkmagenta Darkolivegreen Hash = 0x7bd0e // darkolivegreen Darkorange Hash = 0x8220a // darkorange Darkorchid Hash = 0x93c0a // darkorchid Darksalmon Hash = 0x9800a // darksalmon Darkseagreen Hash = 0x9e10c // darkseagreen Darkslateblue Hash = 0xa350d // darkslateblue Darkslategray Hash = 0x3b40d // darkslategray Darkturquoise Hash = 0x3c10d // darkturquoise Darkviolet Hash = 0x3ce0a // darkviolet Deeppink Hash = 0x27d08 // deeppink Deepskyblue Hash = 0x9530b // deepskyblue Default Hash = 0x5e607 // default Direction Hash = 0xac909 // direction Display Hash = 0x3d807 // display Document Hash = 0x3e608 // document Dodgerblue Hash = 0x3ee0a // dodgerblue Elevation Hash = 0x4bb09 // elevation Empty_Cells Hash = 0x5070b // empty-cells Fantasy Hash = 0x54807 // fantasy Fill Hash = 0x60304 // fill Filter Hash = 0x406 // filter Firebrick Hash = 0x3f809 // firebrick Flex Hash = 0x40104 // flex Float Hash = 0x40505 // float Floralwhite Hash = 0x40a0b // floralwhite Font Hash = 0x10304 // font Font_Face Hash = 0x10309 // font-face Font_Family Hash = 0x4340b // font-family Font_Size Hash = 0x43f09 // font-size Font_Size_Adjust Hash = 0x43f10 // font-size-adjust Font_Stretch Hash = 0x4530c // font-stretch Font_Style Hash = 0x4640a // font-style Font_Variant Hash = 0x46e0c // font-variant Font_Weight Hash = 0x4890b // font-weight Forestgreen Hash = 0x3900b // forestgreen Fuchsia Hash = 0x49407 // fuchsia Gainsboro Hash = 0x8809 // gainsboro Ghostwhite Hash = 0x14c0a // ghostwhite Goldenrod Hash = 0x26309 // goldenrod Greenyellow Hash = 0x8320b // greenyellow Grid Hash = 0x5c904 // grid Height Hash = 0x70006 // height Honeydew Hash = 0x63708 // honeydew Hsl Hash = 0x12203 // hsl Hsla Hash = 0x12204 // hsla Ime_Mode Hash = 0x94d08 // ime-mode Import Hash = 0x54f06 // import Important Hash = 0x54f09 // important Include_Source Hash = 0x88d0e // include-source Indianred Hash = 0x55809 // indianred Inherit Hash = 0x58c07 // inherit Initial Hash = 0x59307 // initial Invert Hash = 0x5b206 // invert Keyframes Hash = 0x41809 // keyframes Large Hash = 0x53305 // large Larger Hash = 0x53306 // larger Lavender Hash = 0x12408 // lavender Lavenderblush Hash = 0x1240d // lavenderblush Lawngreen Hash = 0x9c09 // lawngreen Layer_Background_Color Hash = 0x17616 // layer-background-color Layer_Background_Image Hash = 0x60616 // layer-background-image Layout_Flow Hash = 0x56f0b // layout-flow Layout_Grid Hash = 0x5c20b // layout-grid Layout_Grid_Char Hash = 0xa5a10 // layout-grid-char Layout_Grid_Char_Spacing Hash = 0xa5a18 // layout-grid-char-spacing Layout_Grid_Line Hash = 0x5c210 // layout-grid-line Layout_Grid_Mode Hash = 0x5d810 // layout-grid-mode Layout_Grid_Type Hash = 0x5ed10 // layout-grid-type Left Hash = 0x19f04 // left Lemonchiffon Hash = 0xfa0c // lemonchiffon Letter_Spacing Hash = 0x5a40e // letter-spacing Lightblue Hash = 0x61c09 // lightblue Lightcoral Hash = 0x6250a // lightcoral Lightcyan Hash = 0x66309 // lightcyan Lightgoldenrodyellow Hash = 0x66c14 // lightgoldenrodyellow Lightgray Hash = 0x68b09 // lightgray Lightgreen Hash = 0x6940a // lightgreen Lightpink Hash = 0x69e09 // lightpink Lightsalmon Hash = 0x6a70b // lightsalmon Lightseagreen Hash = 0x6b20d // lightseagreen Lightskyblue Hash = 0x6bf0c // lightskyblue Lightslateblue Hash = 0x6cb0e // lightslateblue Lightsteelblue Hash = 0x6d90e // lightsteelblue Lightyellow Hash = 0x6e70b // lightyellow Limegreen Hash = 0x6f209 // limegreen Line_Break Hash = 0x5ce0a // line-break Line_Height Hash = 0x6fb0b // line-height Linear_Gradient Hash = 0x7060f // linear-gradient List_Style Hash = 0x7150a // list-style List_Style_Image Hash = 0x71510 // list-style-image List_Style_Position Hash = 0x72513 // list-style-position List_Style_Type Hash = 0x7380f // list-style-type Local Hash = 0x74705 // local Magenta Hash = 0x56407 // magenta Margin Hash = 0x2dd06 // margin Margin_Bottom Hash = 0x2dd0d // margin-bottom Margin_Left Hash = 0x2e90b // margin-left Margin_Right Hash = 0x3000c // margin-right Margin_Top Hash = 0x8690a // margin-top Marker_Offset Hash = 0x7550d // marker-offset Marks Hash = 0x76205 // marks Mask Hash = 0x78104 // mask Max_Height Hash = 0x7850a // max-height Max_Width Hash = 0x78f09 // max-width Media Hash = 0xaf105 // media Medium Hash = 0x79806 // medium Mediumaquamarine Hash = 0x79810 // mediumaquamarine Mediumblue Hash = 0x7a80a // mediumblue Mediumorchid Hash = 0x7b20c // mediumorchid Mediumpurple Hash = 0x7cb0c // mediumpurple Mediumseagreen Hash = 0x7d70e // mediumseagreen Mediumslateblue Hash = 0x7e50f // mediumslateblue Mediumspringgreen Hash = 0x7f411 // mediumspringgreen Mediumturquoise Hash = 0x8050f // mediumturquoise Mediumvioletred Hash = 0x8140f // mediumvioletred Midnightblue Hash = 0x8420c // midnightblue Min_Height Hash = 0x84e0a // min-height Min_Width Hash = 0x85809 // min-width Mintcream Hash = 0x86109 // mintcream Mistyrose Hash = 0x87e09 // mistyrose Moccasin Hash = 0x88708 // moccasin Monospace Hash = 0x98709 // monospace Namespace Hash = 0x4b309 // namespace No_Repeat Hash = 0x51a09 // no-repeat None Hash = 0x8c904 // none Normal Hash = 0x9706 // normal Olivedrab Hash = 0x89b09 // olivedrab Orangered Hash = 0x82609 // orangered Orphans Hash = 0x4a307 // orphans Outline Hash = 0x8cd07 // outline Outline_Color Hash = 0x8cd0d // outline-color Outline_Style Hash = 0x8da0d // outline-style Outline_Width Hash = 0x8e70d // outline-width Overflow Hash = 0x52708 // overflow Overflow_X Hash = 0x5270a // overflow-x Overflow_Y Hash = 0x8f40a // overflow-y Padding Hash = 0x2d007 // padding Padding_Bottom Hash = 0x2d00e // padding-bottom Padding_Box Hash = 0x5810b // padding-box Padding_Left Hash = 0x8720c // padding-left Padding_Right Hash = 0x9a30d // padding-right Padding_Top Hash = 0x9990b // padding-top Page Hash = 0x8fe04 // page Page_Break_After Hash = 0x8fe10 // page-break-after Page_Break_Before Hash = 0x90e11 // page-break-before Page_Break_Inside Hash = 0x91f11 // page-break-inside Palegoldenrod Hash = 0x9300d // palegoldenrod Palegreen Hash = 0x95e09 // palegreen Paleturquoise Hash = 0x9670d // paleturquoise Palevioletred Hash = 0x9740d // palevioletred Papayawhip Hash = 0x9900a // papayawhip Pause Hash = 0x9b005 // pause Pause_After Hash = 0x9b00b // pause-after Pause_Before Hash = 0x9bb0c // pause-before Peachpuff Hash = 0x5fb09 // peachpuff Pitch Hash = 0x9c705 // pitch Pitch_Range Hash = 0x9c70b // pitch-range Play_During Hash = 0x3db0b // play-during Position Hash = 0x3808 // position Powderblue Hash = 0x9d20a // powderblue Progid Hash = 0x9dc06 // progid Quotes Hash = 0x9ed06 // quotes Radial_Gradient Hash = 0x90f // radial-gradient Repeat Hash = 0x4d06 // repeat Rgb Hash = 0x4e003 // rgb Rgba Hash = 0x4e004 // rgba Richness Hash = 0x53808 // richness Right Hash = 0x1d205 // right Rosybrown Hash = 0x8f09 // rosybrown Round Hash = 0x3205 // round Royalblue Hash = 0x65a09 // royalblue Ruby_Align Hash = 0x8c00a // ruby-align Ruby_Overhang Hash = 0x7c0d // ruby-overhang Ruby_Position Hash = 0xdc0d // ruby-position Saddlebrown Hash = 0x4a90b // saddlebrown Sandybrown Hash = 0x5110a // sandybrown Sans_Serif Hash = 0x53f0a // sans-serif Scroll Hash = 0x2b306 // scroll Scrollbar_3d_Light_Color Hash = 0x64318 // scrollbar-3d-light-color Scrollbar_Arrow_Color Hash = 0x2b315 // scrollbar-arrow-color Scrollbar_Base_Color Hash = 0x42014 // scrollbar-base-color Scrollbar_Dark_Shadow_Color Hash = 0x7661b // scrollbar-dark-shadow-color Scrollbar_Face_Color Hash = 0x9f214 // scrollbar-face-color Scrollbar_Highlight_Color Hash = 0xaa619 // scrollbar-highlight-color Scrollbar_Shadow_Color Hash = 0xa0616 // scrollbar-shadow-color Scrollbar_Track_Color Hash = 0xa1c15 // scrollbar-track-color Seagreen Hash = 0x6b708 // seagreen Seashell Hash = 0x16f08 // seashell Serif Hash = 0x54405 // serif Size Hash = 0x7104 // size Slateblue Hash = 0x6d009 // slateblue Slategray Hash = 0x3b809 // slategray Small Hash = 0x8ba05 // small Smaller Hash = 0x8ba07 // smaller Solid Hash = 0xa3105 // solid Space Hash = 0x15d05 // space Speak Hash = 0xa4205 // speak Speak_Header Hash = 0xa420c // speak-header Speak_Numeral Hash = 0xa4e0d // speak-numeral Speak_Punctuation Hash = 0xa7211 // speak-punctuation Speech_Rate Hash = 0xa830b // speech-rate Springgreen Hash = 0x7fa0b // springgreen Steelblue Hash = 0x6de09 // steelblue Stress Hash = 0x2ae06 // stress Stroke Hash = 0x44d06 // stroke Supports Hash = 0xa9f08 // supports Table_Layout Hash = 0x5690c // table-layout Text_Align Hash = 0x2a10a // text-align Text_Align_Last Hash = 0x2a10f // text-align-last Text_Autospace Hash = 0x1540e // text-autospace Text_Decoration Hash = 0x4cc0f // text-decoration Text_Decoration_Color Hash = 0x4cc15 // text-decoration-color Text_Emphasis Hash = 0xa8c0d // text-emphasis Text_Emphasis_Color Hash = 0xa8c13 // text-emphasis-color Text_Indent Hash = 0x170b // text-indent Text_Justify Hash = 0x210c // text-justify Text_Kashida_Space Hash = 0x4f612 // text-kashida-space Text_Overflow Hash = 0x5220d // text-overflow Text_Shadow Hash = 0x520b // text-shadow Text_Transform Hash = 0x2f30e // text-transform Text_Underline_Position Hash = 0x30b17 // text-underline-position Top Hash = 0x22203 // top Transition Hash = 0x3390a // transition Transparent Hash = 0x3690b // transparent Turquoise Hash = 0x3c509 // turquoise Unicode_Bidi Hash = 0xabf0c // unicode-bidi Unset Hash = 0xad205 // unset Url Hash = 0x25803 // url Vertical_Align Hash = 0x5b40e // vertical-align Visibility Hash = 0xad70a // visibility Voice_Family Hash = 0xae10c // voice-family Volume Hash = 0xaed06 // volume White Hash = 0x15105 // white White_Space Hash = 0x47e0b // white-space Whitesmoke Hash = 0x4100a // whitesmoke Widows Hash = 0x63e06 // widows Width Hash = 0x11e05 // width Word_Break Hash = 0x5c0a // word-break Word_Spacing Hash = 0x1410c // word-spacing Word_Wrap Hash = 0x57909 // word-wrap Writing_Mode Hash = 0x67f0c // writing-mode X_Large Hash = 0x53107 // x-large X_Small Hash = 0x8b807 // x-small Xx_Large Hash = 0x53008 // xx-large Xx_Small Hash = 0x8b708 // xx-small Yellow Hash = 0x67a06 // yellow Yellowgreen Hash = 0x8370b // yellowgreen Z_Index Hash = 0xaf607 // z-index )
Unique hash definitions to be used instead of strings
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer is the state for the lexer.
func NewLexer ¶
NewLexer returns a new Lexer for a given io.Reader.
Example ¶
l := NewLexer(bytes.NewBufferString("color: red;")) out := "" for { tt, data := l.Next() if tt == ErrorToken { break } else if tt == WhitespaceToken || tt == CommentToken { continue } out += string(data) } fmt.Println(out)
Output: color:red;
func (*Lexer) Err ¶
Err returns the error encountered during lexing, this is often io.EOF but also other errors can be returned.
func (*Lexer) Next ¶
Next returns the next Token. It returns ErrorToken when an error was encountered. Using Err() one can retrieve the error message.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is the state for the parser.
func NewParser ¶
NewParser returns a new CSS parser from an io.Reader. isInline specifies whether this is an inline style attribute.
Example ¶
p := NewParser(bytes.NewBufferString("color: red;"), true) // false because this is the content of an inline style attribute out := "" for { gt, _, data := p.Next() if gt == ErrorGrammar { break } else if gt == AtRuleGrammar || gt == BeginAtRuleGrammar || gt == BeginRulesetGrammar || gt == DeclarationGrammar { out += string(data) if gt == DeclarationGrammar { out += ":" } for _, val := range p.Values() { out += string(val.Data) } if gt == BeginAtRuleGrammar || gt == BeginRulesetGrammar { out += "{" } else if gt == AtRuleGrammar || gt == DeclarationGrammar { out += ";" } } else { out += string(data) } } fmt.Println(out)
Output: color:red;
func (*Parser) Err ¶
Err returns the error encountered during parsing, this is often io.EOF but also other errors can be returned.
func (*Parser) Next ¶
func (p *Parser) Next() (GrammarType, TokenType, []byte)
Next returns the next Grammar. It returns ErrorGrammar when an error was encountered. Using Err() one can retrieve the error message.
type State ¶
type State func(*Parser) GrammarType
State is the state function the parser currently is in.
type TokenType ¶
type TokenType uint32
TokenType determines the type of token, eg. a number or a semicolon.
const ( ErrorToken TokenType = iota // extra token when errors occur IdentToken FunctionToken // rgb( rgba( ... AtKeywordToken // @abc HashToken // #abc StringToken BadStringToken URLToken BadURLToken DelimToken // any unmatched character NumberToken // 5 PercentageToken // 5% DimensionToken // 5em UnicodeRangeToken // U+554A IncludeMatchToken // ~= DashMatchToken // |= PrefixMatchToken // ^= SuffixMatchToken // $= SubstringMatchToken // *= ColumnToken // || WhitespaceToken // space \t \r \n \f CDOToken // <!-- CDCToken // --> ColonToken // : SemicolonToken // ; CommaToken // , LeftBracketToken // [ RightBracketToken // ] LeftParenthesisToken // ( RightParenthesisToken // ) LeftBraceToken // { RightBraceToken // } CommentToken // extra token for comments EmptyToken CustomPropertyNameToken CustomPropertyValueToken )
TokenType values.