Path 1: 1196 calls (0.84)

'' (233) 'foo' (133) 'bar' (68) 'Averlongwordgoeshere' (68) 'banana pancakes' (54) 'baz' (53) 'Coffee' (48) 'COL1' (24) 'test table' (21) 'table capti...

'' (1125) 'table.title' (22) 'table.caption' (21) 'rule.text' (18) 'prompt' (6) 'none' (4)

True (1195) False (1)

None (1196)

Text (1196)

1def render(
2    markup: str,
3    style: Union[str, Style] = "",
4    emoji: bool = True,
5    emoji_variant: Optional[EmojiVariant] = None,
6) -> Text:
7    """Render console markup in to a Text instance.
8
9    Args:
10        markup (str): A string containing console markup.
11        emoji (bool, optional): Also render emoji code. Defaults to True.
12
13    Raises:
14        MarkupError: If there is a syntax error in the markup.
15
16    Returns:
17        Text: A test instance.
18    """
19    emoji_replace = _emoji_replace
20    if "[" not in markup:
21        return Text(
22            emoji_replace(markup, default_variant=emoji_variant) if emoji else markup,
23            style=style,
24        )
25    text = Text(style=style)
26    append = text.append
27    normalize = Style.normalize
28
29    style_stack: List[Tuple[int, Tag]] = []
30    pop = style_stack.pop
31
32    spans: List[Span] = []
33    append_span = spans.append
34
35    _Span = Span
36    _Tag = Tag
37
38    def pop_style(style_name: str) -> Tuple[int, Tag]:
39        """Pop tag matching given style name."""
40        for index, (_, tag) in enumerate(reversed(style_stack), 1):
41            if tag.name == style_name:
42                return pop(-index)
43        raise KeyError(style_name)
44
45    for position, plain_text, tag in _parse(markup):
46        if plain_text is not None:
47            # Handle open brace escapes, where the brace is not part of a tag.
48            plain_text = plain_text.replace("\\[", "[")
49            append(emoji_replace(plain_text) if emoji else plain_text)
50        elif tag is not None:
51            if tag.name.startswith("/"):  # Closing tag
52                style_name = tag.name[1:].strip()
53
54                if style_name:  # explicit close
55                    style_name = normalize(style_name)
56                    try:
57                        start, open_tag = pop_style(style_name)
58                    except KeyError:
59                        raise MarkupError(
60                            f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
61                        ) from None
62                else:  # implicit close
63                    try:
64                        start, open_tag = pop()
65                    except IndexError:
66                        raise MarkupError(
67                            f"closing tag '[/]' at position {position} has nothing to close"
68                        ) from None
69
70                if open_tag.name.startswith("@"):
71                    if open_tag.parameters:
72                        handler_name = ""
73                        parameters = open_tag.parameters.strip()
74                        handler_match = RE_HANDLER.match(parameters)
75                        if handler_match is not None:
76                            handler_name, match_parameters = handler_match.groups()
77                            parameters = (
78                                "()" if match_parameters is None else match_parameters
79                            )
80
81                        try:
82                            meta_params = literal_eval(parameters)
83                        except SyntaxError as error:
84                            raise MarkupError(
85                                f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
86                            )
87                        except Exception as error:
88                            raise MarkupError(
89                                f"error parsing {open_tag.parameters!r}; {error}"
90                            ) from None
91
92                        if handler_name:
93                            meta_params = (
94                                handler_name,
95                                meta_params
96                                if isinstance(meta_params, tuple)
97                                else (meta_params,),
98                            )
99
100                    else:
101                        meta_params = ()
102
103                    append_span(
104                        _Span(
105                            start, len(text), Style(meta={open_tag.name: meta_params})
106                        )
107                    )
108                else:
109                    append_span(_Span(start, len(text), str(open_tag)))
110
111            else:  # Opening tag
112                normalized_tag = _Tag(normalize(tag.name), tag.parameters)
113                style_stack.append((len(text), normalized_tag))
114
115    text_length = len(text)
116    while style_stack:
117        start, tag = style_stack.pop()
118        style = str(tag)
119        if style:
120            append_span(_Span(start, text_length, style))
121
122    text.spans = sorted(spans[::-1], key=attrgetter("start"))
123    return text
            

Path 2: 132 calls (0.09)

'[traceback.title]Traceback [dim](most recent call last)' (18) '[progress.description]test' (10) '[green]Date' (8) '[blue]Title' (8) '[cyan]Production...

'' (89) 'none' (43)

True (132)

None (132)

Text (132)

1def render(
2    markup: str,
3    style: Union[str, Style] = "",
4    emoji: bool = True,
5    emoji_variant: Optional[EmojiVariant] = None,
6) -> Text:
7    """Render console markup in to a Text instance.
8
9    Args:
10        markup (str): A string containing console markup.
11        emoji (bool, optional): Also render emoji code. Defaults to True.
12
13    Raises:
14        MarkupError: If there is a syntax error in the markup.
15
16    Returns:
17        Text: A test instance.
18    """
19    emoji_replace = _emoji_replace
20    if "[" not in markup:
21        return Text(
22            emoji_replace(markup, default_variant=emoji_variant) if emoji else markup,
23            style=style,
24        )
25    text = Text(style=style)
26    append = text.append
27    normalize = Style.normalize
28
29    style_stack: List[Tuple[int, Tag]] = []
30    pop = style_stack.pop
31
32    spans: List[Span] = []
33    append_span = spans.append
34
35    _Span = Span
36    _Tag = Tag
37
38    def pop_style(style_name: str) -> Tuple[int, Tag]:
39        """Pop tag matching given style name."""
40        for index, (_, tag) in enumerate(reversed(style_stack), 1):
41            if tag.name == style_name:
42                return pop(-index)
43        raise KeyError(style_name)
44
45    for position, plain_text, tag in _parse(markup):
46        if plain_text is not None:
47            # Handle open brace escapes, where the brace is not part of a tag.
48            plain_text = plain_text.replace("\\[", "[")
49            append(emoji_replace(plain_text) if emoji else plain_text)
50        elif tag is not None:
51            if tag.name.startswith("/"):  # Closing tag
52                style_name = tag.name[1:].strip()
53
54                if style_name:  # explicit close
55                    style_name = normalize(style_name)
56                    try:
57                        start, open_tag = pop_style(style_name)
58                    except KeyError:
59                        raise MarkupError(
60                            f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
61                        ) from None
62                else:  # implicit close
63                    try:
64                        start, open_tag = pop()
65                    except IndexError:
66                        raise MarkupError(
67                            f"closing tag '[/]' at position {position} has nothing to close"
68                        ) from None
69
70                if open_tag.name.startswith("@"):
71                    if open_tag.parameters:
72                        handler_name = ""
73                        parameters = open_tag.parameters.strip()
74                        handler_match = RE_HANDLER.match(parameters)
75                        if handler_match is not None:
76                            handler_name, match_parameters = handler_match.groups()
77                            parameters = (
78                                "()" if match_parameters is None else match_parameters
79                            )
80
81                        try:
82                            meta_params = literal_eval(parameters)
83                        except SyntaxError as error:
84                            raise MarkupError(
85                                f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
86                            )
87                        except Exception as error:
88                            raise MarkupError(
89                                f"error parsing {open_tag.parameters!r}; {error}"
90                            ) from None
91
92                        if handler_name:
93                            meta_params = (
94                                handler_name,
95                                meta_params
96                                if isinstance(meta_params, tuple)
97                                else (meta_params,),
98                            )
99
100                    else:
101                        meta_params = ()
102
103                    append_span(
104                        _Span(
105                            start, len(text), Style(meta={open_tag.name: meta_params})
106                        )
107                    )
108                else:
109                    append_span(_Span(start, len(text), str(open_tag)))
110
111            else:  # Opening tag
112                normalized_tag = _Tag(normalize(tag.name), tag.parameters)
113                style_stack.append((len(text), normalized_tag))
114
115    text_length = len(text)
116    while style_stack:
117        start, tag = style_stack.pop()
118        style = str(tag)
119        if style:
120            append_span(_Span(start, text_length, style))
121
122    text.spans = sorted(spans[::-1], key=attrgetter("start"))
123    return text
            

Path 3: 28 calls (0.02)

'[bold]$1,332,539,889[/bold]' (8) 'foo 3.141 127.0.0.1 [red]alert[/red]' (3) 'FORMATTER foo 3.141 127.0.0.1 [red]alert[/red] 2023-07-27 16:38:36,464' ...

'' (27) 'bold' (1)

True (28)

None (28)

Text (28)

1def render(
2    markup: str,
3    style: Union[str, Style] = "",
4    emoji: bool = True,
5    emoji_variant: Optional[EmojiVariant] = None,
6) -> Text:
7    """Render console markup in to a Text instance.
8
9    Args:
10        markup (str): A string containing console markup.
11        emoji (bool, optional): Also render emoji code. Defaults to True.
12
13    Raises:
14        MarkupError: If there is a syntax error in the markup.
15
16    Returns:
17        Text: A test instance.
18    """
19    emoji_replace = _emoji_replace
20    if "[" not in markup:
21        return Text(
22            emoji_replace(markup, default_variant=emoji_variant) if emoji else markup,
23            style=style,
24        )
25    text = Text(style=style)
26    append = text.append
27    normalize = Style.normalize
28
29    style_stack: List[Tuple[int, Tag]] = []
30    pop = style_stack.pop
31
32    spans: List[Span] = []
33    append_span = spans.append
34
35    _Span = Span
36    _Tag = Tag
37
38    def pop_style(style_name: str) -> Tuple[int, Tag]:
39        """Pop tag matching given style name."""
40        for index, (_, tag) in enumerate(reversed(style_stack), 1):
41            if tag.name == style_name:
42                return pop(-index)
43        raise KeyError(style_name)
44
45    for position, plain_text, tag in _parse(markup):
46        if plain_text is not None:
47            # Handle open brace escapes, where the brace is not part of a tag.
48            plain_text = plain_text.replace("\\[", "[")
49            append(emoji_replace(plain_text) if emoji else plain_text)
50        elif tag is not None:
51            if tag.name.startswith("/"):  # Closing tag
52                style_name = tag.name[1:].strip()
53
54                if style_name:  # explicit close
55                    style_name = normalize(style_name)
56                    try:
57                        start, open_tag = pop_style(style_name)
58                    except KeyError:
59                        raise MarkupError(
60                            f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
61                        ) from None
62                else:  # implicit close
63                    try:
64                        start, open_tag = pop()
65                    except IndexError:
66                        raise MarkupError(
67                            f"closing tag '[/]' at position {position} has nothing to close"
68                        ) from None
69
70                if open_tag.name.startswith("@"):
71                    if open_tag.parameters:
72                        handler_name = ""
73                        parameters = open_tag.parameters.strip()
74                        handler_match = RE_HANDLER.match(parameters)
75                        if handler_match is not None:
76                            handler_name, match_parameters = handler_match.groups()
77                            parameters = (
78                                "()" if match_parameters is None else match_parameters
79                            )
80
81                        try:
82                            meta_params = literal_eval(parameters)
83                        except SyntaxError as error:
84                            raise MarkupError(
85                                f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
86                            )
87                        except Exception as error:
88                            raise MarkupError(
89                                f"error parsing {open_tag.parameters!r}; {error}"
90                            ) from None
91
92                        if handler_name:
93                            meta_params = (
94                                handler_name,
95                                meta_params
96                                if isinstance(meta_params, tuple)
97                                else (meta_params,),
98                            )
99
100                    else:
101                        meta_params = ()
102
103                    append_span(
104                        _Span(
105                            start, len(text), Style(meta={open_tag.name: meta_params})
106                        )
107                    )
108                else:
109                    append_span(_Span(start, len(text), str(open_tag)))
110
111            else:  # Opening tag
112                normalized_tag = _Tag(normalize(tag.name), tag.parameters)
113                style_stack.append((len(text), normalized_tag))
114
115    text_length = len(text)
116    while style_stack:
117        start, tag = style_stack.pop()
118        style = str(tag)
119        if style:
120            append_span(_Span(start, text_length, style))
121
122    text.spans = sorted(spans[::-1], key=attrgetter("start"))
123    return text
            

Path 4: 14 calls (0.01)

'[b]Solo[/]: A Star Wars Story' (8) 'Word wrap text. Justify [green]left[/], [yellow]center[/], [blue]right[/] or [red]full[/].\n' (1) '[bold]X[/]Y' (...

'' (13) 'pygments.text' (1)

True (14)

None (14)

Text (14)

1def render(
2    markup: str,
3    style: Union[str, Style] = "",
4    emoji: bool = True,
5    emoji_variant: Optional[EmojiVariant] = None,
6) -> Text:
7    """Render console markup in to a Text instance.
8
9    Args:
10        markup (str): A string containing console markup.
11        emoji (bool, optional): Also render emoji code. Defaults to True.
12
13    Raises:
14        MarkupError: If there is a syntax error in the markup.
15
16    Returns:
17        Text: A test instance.
18    """
19    emoji_replace = _emoji_replace
20    if "[" not in markup:
21        return Text(
22            emoji_replace(markup, default_variant=emoji_variant) if emoji else markup,
23            style=style,
24        )
25    text = Text(style=style)
26    append = text.append
27    normalize = Style.normalize
28
29    style_stack: List[Tuple[int, Tag]] = []
30    pop = style_stack.pop
31
32    spans: List[Span] = []
33    append_span = spans.append
34
35    _Span = Span
36    _Tag = Tag
37
38    def pop_style(style_name: str) -> Tuple[int, Tag]:
39        """Pop tag matching given style name."""
40        for index, (_, tag) in enumerate(reversed(style_stack), 1):
41            if tag.name == style_name:
42                return pop(-index)
43        raise KeyError(style_name)
44
45    for position, plain_text, tag in _parse(markup):
46        if plain_text is not None:
47            # Handle open brace escapes, where the brace is not part of a tag.
48            plain_text = plain_text.replace("\\[", "[")
49            append(emoji_replace(plain_text) if emoji else plain_text)
50        elif tag is not None:
51            if tag.name.startswith("/"):  # Closing tag
52                style_name = tag.name[1:].strip()
53
54                if style_name:  # explicit close
55                    style_name = normalize(style_name)
56                    try:
57                        start, open_tag = pop_style(style_name)
58                    except KeyError:
59                        raise MarkupError(
60                            f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
61                        ) from None
62                else:  # implicit close
63                    try:
64                        start, open_tag = pop()
65                    except IndexError:
66                        raise MarkupError(
67                            f"closing tag '[/]' at position {position} has nothing to close"
68                        ) from None
69
70                if open_tag.name.startswith("@"):
71                    if open_tag.parameters:
72                        handler_name = ""
73                        parameters = open_tag.parameters.strip()
74                        handler_match = RE_HANDLER.match(parameters)
75                        if handler_match is not None:
76                            handler_name, match_parameters = handler_match.groups()
77                            parameters = (
78                                "()" if match_parameters is None else match_parameters
79                            )
80
81                        try:
82                            meta_params = literal_eval(parameters)
83                        except SyntaxError as error:
84                            raise MarkupError(
85                                f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
86                            )
87                        except Exception as error:
88                            raise MarkupError(
89                                f"error parsing {open_tag.parameters!r}; {error}"
90                            ) from None
91
92                        if handler_name:
93                            meta_params = (
94                                handler_name,
95                                meta_params
96                                if isinstance(meta_params, tuple)
97                                else (meta_params,),
98                            )
99
100                    else:
101                        meta_params = ()
102
103                    append_span(
104                        _Span(
105                            start, len(text), Style(meta={open_tag.name: meta_params})
106                        )
107                    )
108                else:
109                    append_span(_Span(start, len(text), str(open_tag)))
110
111            else:  # Opening tag
112                normalized_tag = _Tag(normalize(tag.name), tag.parameters)
113                style_stack.append((len(text), normalized_tag))
114
115    text_length = len(text)
116    while style_stack:
117        start, tag = style_stack.pop()
118        style = str(tag)
119        if style:
120            append_span(_Span(start, text_length, style))
121
122    text.spans = sorted(spans[::-1], key=attrgetter("start"))
123    return text
            

Path 5: 10 calls (0.01)

'All ansi styles: [bold]bold[/], [dim]dim[/], [italic]italic[/italic], [underline]underline[/], [strike]strikethrough[/], [reverse]reverse[/], and eve...

'' (10)

True (10)

None (10)

Text (10)

1def render(
2    markup: str,
3    style: Union[str, Style] = "",
4    emoji: bool = True,
5    emoji_variant: Optional[EmojiVariant] = None,
6) -> Text:
7    """Render console markup in to a Text instance.
8
9    Args:
10        markup (str): A string containing console markup.
11        emoji (bool, optional): Also render emoji code. Defaults to True.
12
13    Raises:
14        MarkupError: If there is a syntax error in the markup.
15
16    Returns:
17        Text: A test instance.
18    """
19    emoji_replace = _emoji_replace
20    if "[" not in markup:
21        return Text(
22            emoji_replace(markup, default_variant=emoji_variant) if emoji else markup,
23            style=style,
24        )
25    text = Text(style=style)
26    append = text.append
27    normalize = Style.normalize
28
29    style_stack: List[Tuple[int, Tag]] = []
30    pop = style_stack.pop
31
32    spans: List[Span] = []
33    append_span = spans.append
34
35    _Span = Span
36    _Tag = Tag
37
38    def pop_style(style_name: str) -> Tuple[int, Tag]:
39        """Pop tag matching given style name."""
40        for index, (_, tag) in enumerate(reversed(style_stack), 1):
41            if tag.name == style_name:
42                return pop(-index)
43        raise KeyError(style_name)
44
45    for position, plain_text, tag in _parse(markup):
46        if plain_text is not None:
47            # Handle open brace escapes, where the brace is not part of a tag.
48            plain_text = plain_text.replace("\\[", "[")
49            append(emoji_replace(plain_text) if emoji else plain_text)
50        elif tag is not None:
51            if tag.name.startswith("/"):  # Closing tag
52                style_name = tag.name[1:].strip()
53
54                if style_name:  # explicit close
55                    style_name = normalize(style_name)
56                    try:
57                        start, open_tag = pop_style(style_name)
58                    except KeyError:
59                        raise MarkupError(
60                            f"closing tag '{tag.markup}' at position {position} doesn't match any open tag"
61                        ) from None
62                else:  # implicit close
63                    try:
64                        start, open_tag = pop()
65                    except IndexError:
66                        raise MarkupError(
67                            f"closing tag '[/]' at position {position} has nothing to close"
68                        ) from None
69
70                if open_tag.name.startswith("@"):
71                    if open_tag.parameters:
72                        handler_name = ""
73                        parameters = open_tag.parameters.strip()
74                        handler_match = RE_HANDLER.match(parameters)
75                        if handler_match is not None:
76                            handler_name, match_parameters = handler_match.groups()
77                            parameters = (
78                                "()" if match_parameters is None else match_parameters
79                            )
80
81                        try:
82                            meta_params = literal_eval(parameters)
83                        except SyntaxError as error:
84                            raise MarkupError(
85                                f"error parsing {parameters!r} in {open_tag.parameters!r}; {error.msg}"
86                            )
87                        except Exception as error:
88                            raise MarkupError(
89                                f"error parsing {open_tag.parameters!r}; {error}"
90                            ) from None
91
92                        if handler_name:
93                            meta_params = (
94                                handler_name,
95                                meta_params
96                                if isinstance(meta_params, tuple)
97                                else (meta_params,),
98                            )
99
100                    else:
101                        meta_params = ()
102
103                    append_span(
104                        _Span(
105                            start, len(text), Style(meta={open_tag.name: meta_params})
106                        )
107                    )
108                else:
109                    append_span(_Span(start, len(text), str(open_tag)))
110
111            else:  # Opening tag
112                normalized_tag = _Tag(normalize(tag.name), tag.parameters)
113                style_stack.append((len(text), normalized_tag))
114
115    text_length = len(text)
116    while style_stack:
117        start, tag = style_stack.pop()
118        style = str(tag)
119        if style:
120            append_span(_Span(start, text_length, style))
121
122    text.spans = sorted(spans[::-1], key=attrgetter("start"))
123    return text
            

Path 6: 10 calls (0.01)

'Star Wars Ep. [b]I[/b]: [i]The phantom Menace' (8) "[b]foo