Changeset 2851:12592b930e9e in livinglogic.python.xist

Show
Ignore:
Timestamp:
08/03/07 16:56:14 (12 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add support for @media rules to html.itercssrules().

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/ns/html.py

    r2849 r2851  
    14261426                for rule in self._doimport(wantmedia, sheet, href): 
    14271427                    yield rule 
     1428            elif rule.type == css.CSSRule.MEDIA_RULE: 
     1429                if wantmedia in rule.media: 
     1430                    for subrule in rule.cssRules: 
     1431                        _fixurl(subrule, base) 
     1432                        yield subrule 
    14281433            elif rule.type == css.CSSRule.STYLE_RULE: 
    14291434                _fixurl(rule, base) 
  • test/test_html.py

    r2849 r2851  
    8282 
    8383 
    84 def test_applycss6(): 
     84def test_applycss_media(): 
     85    # Check that media="screen" picks up the media stylesheet 
    8586    with html.html() as e: 
    8687        with html.head(): 
     
    9394    assert str(e.walknode(html.p)[0].attrs.style) == "color: red;" 
    9495 
    95  
    96 def test_applycss7(): 
     96    # Check that media="screen" doesn't pick up the print stylesheet 
    9797    with html.html() as e: 
    9898        with html.head(): 
     
    103103    html.applycss(e, media="print") 
    104104 
    105     # Check that media="screen" doesn't pick up the print stylesheet 
    106105    assert str(e.walknode(html.p)[0].attrs.style) == "" 
     106 
     107    # Check that @media rules are treated properly 
     108    with html.html() as e: 
     109        with html.head(): 
     110            +html.style("@media screen { p {color: red;}}", type="text/css") 
     111        with html.body(): 
     112            +html.p("gurk") 
     113 
     114    html.applycss(e, media="screen") 
     115 
     116    assert str(e.walknode(html.p)[0].attrs.style) == "color: red;" 
     117 
     118    with html.html() as e: 
     119        with html.head(): 
     120            +html.style("@media screen { p {color: red;}}", type="text/css") 
     121        with html.body(): 
     122            +html.p("gurk") 
     123 
     124    html.applycss(e, media="print") 
     125 
     126    assert str(e.walknode(html.p)[0].attrs.style) == ""