Search code examples
pythonhtmlcsscss-selectorscss-parsing

Stylesheet parsing error for [dir=rtl] when using cssutils python module


I'm parsing a css stylesheet with cssutils python module. The parser emits an error when reaching the "[dir=ltr] div.row div.label" selector.

I would like to find a way to modify the CSS to make the parser happy and maintain the same functionality.

What would be the standard way for this:

div.row div.label {
 float: left;
 width: 18%;
 text-align: right;
}
div.row div.formw {
 width: 80%;
}
[dir=ltr] div.row div.label, [dir=rtl] div.row div.formw {
 float: left;
 text-align: right;
}
[dir=rtl] div.row div.label, [dir=ltr] div.row div.formw {
 float: right;
 text-align: left;
}

Note: "dir" is used to control the direction of the text for languages like hebrew or arabic.

http://www.unics.uni-hannover.de/nhtcapri/bidirectional-text.html


Solution

  • it's a bit slower but

    *[dir=ltr] div.row div.label, *[dir=rtl] div.row div.formw {
     float: left;
     text-align: right;
    }
    *[dir=rtl] div.row div.label, *[dir=ltr] div.row div.formw {
     float: right;
     text-align: left;
    }
    

    should work. Obviously change * with the element with this attribute if is possible