108) -> Text:
109 """Render console markup in to a Text instance.
110
111 Args:
112 markup (str): A string containing console markup.
113 emoji (bool, optional): Also render emoji code. Defaults to True.
114
115 Raises:
116 MarkupError: If there is a syntax error in the markup.
117
118 Returns:
119 Text: A test instance.
120 """
121 emoji_replace = _emoji_replace
122 if "[" not in markup:
123 return Text(
124 emoji_replace(markup, default_variant=emoji_variant)
if emoji
else markup,
125 style=style,
126 )
127 text = Text(style=style)
130
131 style_stack: List[Tuple[int, Tag]] = []
133
134 spans: List[Span] = []
136
137 _Span = Span
138 _Tag = Tag
139
140 def pop_style(style_name: str) -> Tuple[int, Tag]:
141 """Pop tag matching given style name."""
144 return pop(-index)
146
147 for position, plain_text, tag in _parse(markup):
148 if plain_text is not None:
149
152 elif tag is not None:
155
156 if style_name:
157 style_name = normalize(style_name)
158 try:
160 except KeyError:
161 raise MarkupError(
162 f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
163 ) from None
164 else:
165 try:
166 start, open_tag = pop()
167 except IndexError:
168 raise MarkupError(
169 f"closing tag '[/]' at position {position} has nothing to close"
170 ) from None
171
174 handler_name = ""
177 if handler_match is not None:
179 parameters = (
180 "()" if match_parameters is None else match_parameters
181 )
182
183 try:
184 meta_params = literal_eval(parameters)
185 except SyntaxError as error:
186 raise MarkupError(
187 f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
188 )
189 except Exception as error:
190 raise MarkupError(
191 f"error parsing {open_tag.parameters!r}; {error}"
192 ) from None
193
194 if handler_name:
195 meta_params = (
196 handler_name,
197 meta_params
199 else (meta_params,),
200 )
201
202 else:
203 meta_params = ()
204
208 )
209 )
210 else:
212
213 else:
216
217 text_length =
len(text)
218 while style_stack:
220 style = str(tag)
221 if style:
223
224 text.spans = sorted(spans[::-1], key=attrgetter(
"start"))
225 return text
226
227