CSS-DOM
view release on metacpan or search on metacpan
lib/CSS/DOM/PropertyParser.pm view on Meta::CPAN
$prop_parser->match('background-position','top left');
'top left', 'CSS::DOM::Value', CSS_CUSTOM, 'top left'
$prop_parser->match('background-position','inherit');
'inherit', 'CSS::DOM::Value', CSS_INHERIT
$prop_parser->match('top','1em');
'1em', $prim, type => CSS_EMS, value => 1
$prop_parser->match('content','"\66oo"');
'"\66oo"', $prim, type => CSS_STRING, value => foo
$prop_parser->match('clip','rect( 5px, 6px, 7px, 8px )');
'rect(5px, 6px, 7px, 8px)', $prim,
type => CSS_RECT,
value => [ [ type => CSS_PX, value => 5 ],
[ type => CSS_PX, value => 6 ],
[ type => CSS_PX, value => 7 ],
[ type => CSS_PX, value => 8 ] ]
$prop_parser->match('color','#fff');
'#fff', $prim, type => CSS_RGBCOLOR, value => '#fff'
$prop_parser->match('color','rgba(255,0,0,.5)');
'rgba(255, 0, 0, .5)', $prim, type => CSS_RGBCOLOR,
value => [ [ type => CSS_NUMBER, value => 255 ],
[ type => CSS_NUMBER, value => 0 ],
[ type => CSS_NUMBER, value => 0 ],
[ type => CSS_NUMBER, value => .5 ] ]
$prop_parser->match('content','counter(foo,disc)');
'counter(foo, disc)', $list,
separator => ' ',
values => [
[
type => CSS_COUNTER,
value => [
[ type => CSS_IDENT, value => 'foo' ],
undef,
[ type => CSS_IDENT, value => 'disc' ],
]
],
]
$prop_parser->match('font-family','Lucida Grande');
'Lucida Grande', $list,
separator => ', ',
values => [
[ type => CSS_STRING, value => 'Lucida Grande' ],
]
$prop_parser->match('counter-reset','Lucida Grande');
'Lucida Grande', $list,
separator => ' ',
values => [
[ type => CSS_IDENT, value => 'Lucida' ],
[ type => CSS_IDENT, value => 'Grande' ],
]
$prop_parser->match('font','bold 13px Lucida Grande');
{
'font-style' => [
'normal', $prim, type => CSS_IDENT, value => 'normal'
],
'font-variant' => [
'normal', $prim, type => CSS_IDENT, value => 'normal'
],
'font-weight' => [
'bold', $prim, type => CSS_IDENT, value => 'bold'
],
'font-size' => [ '13px', $prim, type => CSS_PX, value => 13 ],
'line-height' => [
'normal', $prim, type => CSS_IDENT, value => 'normal'
],
'font-family' => [ 'Lucida Grande', $list,
separator => ', ',
values => [
[ type => CSS_STRING, value => 'Lucida Grande' ],
]
]
}
=item whatever
~~~
CSS::DOM::Style currently relies on the internal formatting of the hash
refs. I want to allow custom property parser classes to do away with hash
refs
altogether, so I will need extra methods here that Style will use instead.
=back
=end comment
=head1 HOW INDIVIDUAL PROPERTIES ARE SPECIFIED
Before you read this the first time, look at the L</Example> below, and
then come back and use this for reference.
The specification for an individual property is a hash ref. There are
several keys that each hash ref can have:
=over
=item format
This is set to a string that describes the format of the property. The
syntax used is based on the CSS 2.1 spec, but is not exactly the same.
Unlike regular expressions, these formats are applied to properties on a
token-by-token basis, not one character at a time. (This means that
C<100|200> cannot be written as C<[1|2]00>, as that would mean
S<C<1 00 | 2 00>>.)
Whitespace is ignored in the format and in the CSS property except as a
token separator.
There are several metachars (in order of precedence):
[...] grouping (like (?:...) )
(...) capturing group (just like a regexp)
? optional
* zero or more
+ one or more
|| alternates that can come in any order and are optional,
but at least one must be specified (the order will be
retained if possible)
| alternates, exactly one of which is required
In addition, the following datatypes can be specified in angle brackets:
lib/CSS/DOM/PropertyParser.pm view on Meta::CPAN
inherit => 1,
},
display => {
format => 'inline|block|list-item|run-in|inline-block|table|
inline-table|table-row-group|table-header-group|
table-footer-group|table-row|table-column-group|
table-column|table-cell|table-caption|none',
default => 'inline',
inherit => 0,
},
elevation => {
format => '<angle>|below|level|above|higher|lower',
default => '0',
inherit => 1,
},
'empty-cells' => {
format => 'show|hide',
default => 'show',
inherit => 1,
},
float => {
format => 'left|right|none',
default => 'none',
inherit => 0,
},
'font-family' => { # aka typeface
format => '(serif|sans-serif|cursive|fantasy|monospace|
<str/words>)
[,(serif|sans-serif|cursive|fantasy|monospace|
<str/words>)]*',
default => 'Times, serif',
inherit => 1,
list => 1,
},
'font-size' => {
format => 'xx-small|x-small|small|medium|large|x-large|xx-large|
larger|smaller|<length>|<percentage>',
default => 'medium',
inherit => 1,
},
'font-style' => {
format => 'normal|italic|oblique',
default => 'normal',
inherit => 1,
},
'font-variant' => {
format => 'normal | small-caps',
default => 'normal',
inherit => 1,
},
'font-weight' => {
format => 'normal|bold|bolder|lighter|
100|200|300|400|500|600|700|800|900',
default => 'normal',
inherit => 1,
},
font => {
format => "[ 'font-style' || 'font-variant' || 'font-weight' ]?
'font-size' [ / 'line-height' ]? 'font-family'",
special_values => {
caption => '13px Lucida Grande, sans-serif',
icon => '13px Lucida Grande, sans-serif',
menu => '13px Lucida Grande, sans-serif',
'message-box' => '13px Lucida Grande, sans-serif',
'small-caption' => '11px Lucida Grande, sans-serif',
'status-bar' => '10px Lucida Grande, sans-serif',
},
serialise => sub {
my $p = shift;
my $ret = '';
for(qw/ style variant weight /) {
length $p->{"font-$_"}
and $ret .= $p->{"font-$_"}." ";
}
$ret .= length $p->{'font-size'}
? $p->{'font-size'}
: 'medium';
$ret .= "/$p->{'line-height'}" if length $p->{'line-height'};
$ret .= " " . ($p->{'font-family'} || "Times, serif");
$ret
},
},
height => {
format => '<length>|<percentage>|auto',
default => 'auto',
inherit => 0,
},
left => {
format => '<length>|<percentage>|auto',
default => 'auto',
inherit => 0,
},
'letter-spacing' => { # aka tracking
format => 'normal|<length>',
default => 'normal',
inherit => 1,
},
'line-height' => { # aka leading
format => 'normal|<number>|<length>|<percentage>',
default => "normal",
inherit => 1,
},
'list-style-image' => {
format => '<url>|none',
default => 'none',
inherit => 1,
( run in 0.550 second using v1.01-cache-2.11-cpan-39bf76dae61 )