Return state from tag and `markdown` attribute. One of 'block', 'span', or 'off'.
(self, tag, attrs: Mapping[str, str])
| 79 | return element |
| 80 | |
| 81 | def get_state(self, tag, attrs: Mapping[str, str]) -> Literal['block', 'span', 'off', None]: |
| 82 | """ Return state from tag and `markdown` attribute. One of 'block', 'span', or 'off'. """ |
| 83 | md_attr = attrs.get('markdown', '0') |
| 84 | if md_attr == 'markdown': |
| 85 | # `<tag markdown>` is the same as `<tag markdown='1'>`. |
| 86 | md_attr = '1' |
| 87 | parent_state = self.mdstate[-1] if self.mdstate else None |
| 88 | if parent_state == 'off' or (parent_state == 'span' and md_attr != '0'): |
| 89 | # Only use the parent state if it is more restrictive than the markdown attribute. |
| 90 | md_attr = parent_state |
| 91 | if ((md_attr == '1' and tag in self.block_tags) or |
| 92 | (md_attr == 'block' and tag in self.span_and_blocks_tags)): |
| 93 | return 'block' |
| 94 | elif ((md_attr == '1' and tag in self.span_tags) or |
| 95 | (md_attr == 'span' and tag in self.span_and_blocks_tags)): |
| 96 | return 'span' |
| 97 | elif tag in self.block_level_tags: |
| 98 | return 'off' |
| 99 | else: # pragma: no cover |
| 100 | return None |
| 101 | |
| 102 | def handle_starttag(self, tag, attrs): |
| 103 | # Handle tags that should always be empty and do not specify a closing tag |