Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do not know of a complete, pre-packaged solution.</p> <p><a href="https://metacpan.org/pod/CSS::DOM" rel="nofollow noreferrer">CSS::DOM</a>'s <code>compute_style</code> is subject to pretty much the same caveats as <em>emogrifier</em> above. That module, in conjunction with <a href="https://metacpan.org/pod/HTML::TokeParser" rel="nofollow noreferrer">HTML::TokeParser</a> ought to be usable to cook up something.</p> <p><strong>Update:</strong> Here is a buggy mish-mash of things:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use CSS::DOM; use File::Slurp; use HTML::DOM; use HTML::TokeParser; die "convert html_file css_file" unless @ARGV == 2; my ($html_file, $css_file) = @ARGV; my $html_parser = HTML::TokeParser-&gt;new($html_file) or die "Cannot open '$html_file': $!"; my $sheet = CSS::DOM::parse( scalar read_file $css_file ); while ( my $token = $html_parser-&gt;get_token ) { my $type = $token-&gt;[0]; my $text = $type eq 'T' ? $token-&gt;[1] : $token-&gt;[-1]; if ( $type eq 'S' ) { unless ( skip( $token-&gt;[1] ) ) { $text = insert_computed_style($sheet, $token); } } print $text; } sub insert_computed_style { my ($sheet, $token) = @_; my ($tag, $attr, $attrseq) = @$token[1 .. 3]; my $doc = HTML::DOM-&gt;new; my $element = $doc-&gt;createElement($tag); for my $attr_name ( @$attrseq ) { $element-&gt;setAttribute($attr_name, $attr-&gt;{$attr_name}); } my $style = CSS::DOM::compute_style( element =&gt; $element, user_sheet =&gt; $sheet ); my @attrseq = (style =&gt; grep { lc $_ ne 'style' } @$attrseq ); $attr-&gt;{style} = $style-&gt;cssText; my $text .= join(" ", "&lt;$tag", map{ qq/$_='$attr-&gt;{$_}'/ } @attrseq ); $text .= '&gt;'; return $text; } sub skip { my ($tag) = @_; $tag = lc $tag; return 1 if $tag =~ /^(?:h(?:ead|tml)|link|meta|script|title)$/; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload