Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tinycss
- def has_em_or_percent_font_size_definition(css):
- parser = tinycss.make_parser("page3")
- stylesheet = parser.parse_stylesheet(css)
- for rule in stylesheet.rules:
- for declaration in rule.declarations:
- if declaration.name == "font-size": #todo: try to detect font sizes defined under the `font` category name rather than font-size specifically
- token = declaration.value[0] #todo: figure out what to do if there's more than one token. (can that ever even happen?)
- if token.unit in {"em", "%"}:
- return True
- return False
- test_cases = [
- ".foobar{font-size: 10em; background-color:blue} #bazqux{background-color:red}",
- "div{background-color: green}"
- ]
- for idx, css in enumerate(test_cases):
- print("Test case #{}: {}".format(idx, css))
- if has_em_or_percent_font_size_definition(css):
- print(" Contains an em or % font-size definition")
- else:
- print(" Does not contain an em or % font-size definition")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement