Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import tinycss
  2.  
  3. def has_em_or_percent_font_size_definition(css):
  4. parser = tinycss.make_parser("page3")
  5. stylesheet = parser.parse_stylesheet(css)
  6. for rule in stylesheet.rules:
  7. for declaration in rule.declarations:
  8. if declaration.name == "font-size": #todo: try to detect font sizes defined under the `font` category name rather than font-size specifically
  9. token = declaration.value[0] #todo: figure out what to do if there's more than one token. (can that ever even happen?)
  10. if token.unit in {"em", "%"}:
  11. return True
  12. return False
  13.  
  14. test_cases = [
  15. ".foobar{font-size: 10em; background-color:blue} #bazqux{background-color:red}",
  16. "div{background-color: green}"
  17. ]
  18.  
  19. for idx, css in enumerate(test_cases):
  20. print("Test case #{}: {}".format(idx, css))
  21. if has_em_or_percent_font_size_definition(css):
  22. print(" Contains an em or % font-size definition")
  23. else:
  24. print(" Does not contain an em or % font-size definition")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement