16
16
from rich .emoji import Emoji
17
17
from rich .highlighter import RegexHighlighter
18
18
from rich .markdown import Markdown
19
+ from rich .markup import escape
19
20
from rich .padding import Padding
20
21
from rich .panel import Panel
21
22
from rich .table import Table
22
23
from rich .text import Text
23
24
from rich .theme import Theme
25
+ from rich .traceback import Traceback
26
+ from typer .models import DeveloperExceptionConfig
24
27
25
28
if sys .version_info >= (3 , 9 ):
26
29
from typing import Literal
@@ -727,6 +730,11 @@ def rich_abort_error() -> None:
727
730
console .print (ABORTED_TEXT , style = STYLE_ABORTED )
728
731
729
732
733
+ def escape_before_html_export (input_text : str ) -> str :
734
+ """Ensure that the input string can be used for HTML export."""
735
+ return escape (input_text ).strip ()
736
+
737
+
730
738
def rich_to_html (input_text : str ) -> str :
731
739
"""Print the HTML version of a rich-formatted input string.
732
740
@@ -744,3 +752,19 @@ def rich_render_text(text: str) -> str:
744
752
"""Remove rich tags and render a pure text representation"""
745
753
console = _get_rich_console ()
746
754
return "" .join (segment .text for segment in console .render (text )).rstrip ("\n " )
755
+
756
+
757
+ def get_traceback (
758
+ exc : BaseException ,
759
+ exception_config : DeveloperExceptionConfig ,
760
+ internal_dir_names : List [str ],
761
+ ) -> Traceback :
762
+ rich_tb = Traceback .from_exception (
763
+ type (exc ),
764
+ exc ,
765
+ exc .__traceback__ ,
766
+ show_locals = exception_config .pretty_exceptions_show_locals ,
767
+ suppress = internal_dir_names ,
768
+ width = MAX_WIDTH ,
769
+ )
770
+ return rich_tb
0 commit comments