[![Build Status](https://travis-ci.org/css-raku/CSS-raku.svg?branch=master)](https://travis-ci.org/css-raku/CSS-raku) class CSS --------- CSS Stylesheet processing Synopsis -------- use CSS; use CSS::Properties; use CSS::Units :px; # define 'px' postfix operator use CSS::TagSet::XHTML; use LibXML::Document; my $string = q:to<\_(ツ)_/>;

This is a heading

This is a sub-heading

This is another heading

This is a paragraph.

This is a div
\_(ツ)_/ my LibXML::Document $doc .= parse: :$string, :html; # define a selection media my CSS::Media $media .= new: :type, :width(480px), :height(640px), :color; # Create a tag-set for XHTML specific loading of style-sheets and styling my CSS::TagSet::XHTML $tag-set .= new(); my CSS $css .= new: :$doc, :$tag-set, :$media, :inherit; # show some computed styles, based on CSS Selectors, media, inline styles and xhtml tags my CSS::Properties $body-props = $css.style('/html/body'); say $body-props.font-size; # 12pt say $body-props; # background-color:powderblue; display:block; font-size:12pt; margin:8px; unicode-bidi:embed; say $css.style('/html/body/h1[1]'); # color:blue; display:block; font-size:12pt; font-weight:bolder; margin-bottom:0.67em; margin-top:0.67em; unicode-bidi:embed; say $css.style('/html/body/div'); # color:green; display:block; font-size:10pt; unicode-bidi:embed; say $css.style($doc.first('/html/body/div')); # color:green; display:block; font-size:10pt; unicode-bidi:embed; Description ----------- [CSS](https://css-raku.github.io/CSS-raku) is a module for parsing style-sheets and applying them to HTML or XML documents. This module aims to be W3C compliant and complete, including: style-sheets, media specific and inline styling and the application of HTML specific styling (based on tags and attributes). Methods ------- ### method new method new( LibXML::Document :$doc!, # document to be styled. CSS::Stylesheet :$stylesheet!, # stylesheet to apply CSS::TagSet :$tag-set, # tag-specific styling CSS::Media :$media, # target media Bool :$inherit = True, # perform property inheritance ) returns CSS; In particular, the `CSS::TagSet :$tag-set` options specifies a tag-specific styler; For example CSS::TagSet::XHTML. ### method style multi method style(LibXML::Element:D $elem) returns CSS::Properties; multi method style(Str:D $xpath) returns CSS::Properties; Computes a style for an individual element, or XPath to an element. ### method prune method prune(LibXML::Element $node? --> LibXML::Element) Removes all XML nodes with CSS property `display:none;`, giving an approximate representation of a CSS rendering tree. For example, for a XHTML tag-set the `head` element will be removed, along with any other elements that have had `display:none;' applied to them via inline CSS or CSS Selectors. By default, this method acts on the root element of the associated $.doc XML document. Classes ------- * [CSS::TagSet](https://css-raku.github.io/CSS-raku/TagSet) - CSS TagSet Role * [CSS::TagSet::XHTML](https://css-raku.github.io/CSS-raku/TagSet/XHTML) - Implements XHTML specific styling * [CSS::TagSet::Pango](https://css-raku.github.io/CSS-raku/TagSet/Pango) - Implements Pango styling * [CSS::TagSet::TaggedPDF](https://css-raku.github.io/CSS-raku/TagSet/TaggedPDF) - (*UNDER CONSTRUCTION*) Implements Taged PDF styling Utility Scripts --------------- * `css-tidy.raku [--/optimize] [--/terse] [--/warn] [--lax] [--color=names|values|masks] []` Rebuild a CSS Style-sheet with various checks and optimizations. * `css-inliner.raku input.xml [output.xml] --style=file.css --prune --tags --type=html|pango|pdf --inherit Apply internal or external stylesheets to per-element 'style' attributes See Also -------- * [CSS::Style](https://css-raku.github.io/CSS-raku/Style) - CSS Stylesheet representations * [CSS::Module](https://css-raku.github.io/CSS-Module-raku) - CSS Module Raku module * [CSS::Properties](https://css-raku.github.io/CSS-Properties-raku) - CSS Properties Raku module * [LibXML](https://libxml-raku.github.io/LibXML-raku/) - LibXML Raku module Todo ---- - HTML linked style-sheets, e.g. `` - CSS imported style-sheets, e.g. `@import url("navigation.css")` - Other At-Rule variants (in addition to `@media` and `@import`) `@document`, `@page`, `@font-face`