MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / get_state

Method get_state

markdown/extensions/md_in_html.py:89–108  ·  view source on GitHub ↗

Return state from tag and `markdown` attribute. One of 'block', 'span', or 'off'.

(self, tag, attrs: Mapping[str, str])

Source from the content-addressed store, hash-verified

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

Callers 1

handle_starttagMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected