Coverage for phml\nodes\types.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-08 11:07 -0600

1"""Here is a collection of type annotations 

2""" 

3 

4from typing import Any 

5 

6__all__ = ["Properties"] 

7 

8Data = dict 

9 

10PropertyName = str 

11"""Property names are keys on Properties objects and reflect HTML, SVG, ARIA, XML, XMLNS, 

12or XLink attribute names. Often, they have the same value as the corresponding attribute 

13(for example, id is a property name reflecting the id attribute name), but there are some 

14notable differences. 

15 

16 These rules aren't simple. Use hastscript (or property-information directly) to help. 

17 

18The following rules are used to transform HTML attribute names to property names. These 

19rules are based on how ARIA is reflected in the DOM ([ARIA]), and differs from how some 

20(older) HTML attributes are reflected in the DOM. 

21 

22Any name referencing a combinations of multiple words (such as “stroke miter limit”) becomes 

23a camelcased property name capitalizing each word boundary. This includes combinations 

24that are sometimes written as several words. For example, `stroke-miterlimit` becomes 

25`strokeMiterLimit`, `autocorrect` becomes `autoCorrect`, and `allowfullscreen` becomes 

26`allowFullScreen`. 

27 

28Any name that can be hyphenated, becomes a camelcased property name capitalizing each boundary. 

29For example, “read-only” becomes `readOnly`. 

30 

31Compound words that are not used with spaces or hyphens are treated as a normal word and the 

32previous rules apply. For example, “placeholder”, “strikethrough”, and “playback” stay the same. 

33 

34Acronyms in names are treated as a normal word and the previous rules apply. For example, 

35`itemid` become `itemId` and `bgcolor` becomes `bgColor`. 

36""" 

37 

38PropertyValue = Any 

39"""Property values should reflect the data type determined by their property name. 

40For example, the HTML `<div hidden></div>` has a `hidden` attribute, which is reflected 

41as a `hidden` property name set to the property value `true`, and `<input minlength="5">`, 

42which has a `minlength` attribute, is reflected as a `minLength` property name set to the 

43property value `5`. 

44 

45 In JSON, the value `null` must be treated as if the property was not included. 

46 In JavaScript, both `null` and `undefined` must be similarly ignored. 

47 

48The DOM has strict rules on how it coerces HTML to expected values, 

49whereas hast is more lenient in how it reflects the source. Where the DOM treats 

50`<div hidden="no"></div>` as having a value of `true` and `<img width="yes">` 

51as having a value of `0`, these should be reflected as `'no'` and `'yes'`, respectively, in hast. 

52 

53 The reason for this is to allow plugins and utilities to inspect these non-standard values. 

54 

55The DOM also specifies comma separated and space separated lists attribute values. 

56In hast, these should be treated as ordered lists. For example, `<div class="alpha bravo"></div>` 

57is represented as `['alpha', 'bravo']`. 

58 

59 There's no special format for the property value of the `style` property name. 

60""" 

61 

62Properties = dict[PropertyName, PropertyValue] 

63"""Properties represents information associated with an element. 

64 

65Every field must be a PropertyName and every value a PropertyValue. 

66"""