Method: rich.markdown.Markdown.__rich_console__
Calls: 4, Exceptions: 4, Paths: 4Back
Path 1: 1 calls (0.25)
Console (1)
ConsoleOptions (1)
Segment (42)
StopIteration (1)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 """Render markdown to the console."""
5 style = console.get_style(self.style, default="none")
6 options = options.update(height=None)
7 context = MarkdownContext(
8 console,
9 options,
10 style,
11 inline_code_lexer=self.inline_code_lexer,
12 inline_code_theme=self.inline_code_theme,
13 )
14 nodes = self.parsed.walker()
15 inlines = self.inlines
16 new_line = False
17 for current, entering in nodes:
18 node_type = current.t
19 if node_type in ("html_inline", "html_block", "text"):
20 context.on_text(current.literal.replace("\n", " "), node_type)
21 elif node_type == "linebreak":
22 if entering:
23 context.on_text("\n", node_type)
24 elif node_type == "softbreak":
25 if entering:
26 context.on_text(" ", node_type)
27 elif node_type == "link":
28 if entering:
29 link_style = console.get_style("markdown.link", default="none")
30 if self.hyperlinks:
31 link_style += Style(link=current.destination)
32 context.enter_style(link_style)
33 else:
34 context.leave_style()
35 if not self.hyperlinks:
36 context.on_text(" (", node_type)
37 style = Style(underline=True) + console.get_style(
38 "markdown.link_url", default="none"
39 )
40 context.enter_style(style)
41 context.on_text(current.destination, node_type)
42 context.leave_style()
43 context.on_text(")", node_type)
44 elif node_type in inlines:
45 if current.is_container():
46 if entering:
47 context.enter_style(f"markdown.{node_type}")
48 else:
49 context.leave_style()
50 else:
51 context.enter_style(f"markdown.{node_type}")
52 if current.literal:
53 context.on_text(current.literal, node_type)
54 context.leave_style()
55 else:
56 element_class = self.elements.get(node_type) or UnknownElement
57 if current.is_container():
58 if entering:
59 element = element_class.create(self, current)
60 context.stack.push(element)
61 element.on_enter(context)
62 else:
63 element = context.stack.pop()
64 if context.stack:
65 if context.stack.top.on_child_close(context, element):
66 if new_line:
67 yield Segment("\n")
68 yield from console.render(element, context.options)
69 element.on_leave(context)
70 else:
71 element.on_leave(context)
72 else:
73 element.on_leave(context)
74 yield from console.render(element, context.options)
75 new_line = element.new_line
76 else:
77 element = element_class.create(self, current)
78
79 context.stack.push(element)
80 element.on_enter(context)
81 if current.literal:
82 element.on_text(context, current.literal.rstrip())
83 context.stack.pop()
84 if context.stack.top.on_child_close(context, element):
85 if new_line:
86 yield Segment("\n")
87 yield from console.render(element, context.options)
88 element.on_leave(context)
89 else:
90 element.on_leave(context)
91 new_line = element.new_line
Path 2: 1 calls (0.25)
Console (1)
ConsoleOptions (1)
Segment (149)
StopIteration (1)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 """Render markdown to the console."""
5 style = console.get_style(self.style, default="none")
6 options = options.update(height=None)
7 context = MarkdownContext(
8 console,
9 options,
10 style,
11 inline_code_lexer=self.inline_code_lexer,
12 inline_code_theme=self.inline_code_theme,
13 )
14 nodes = self.parsed.walker()
15 inlines = self.inlines
16 new_line = False
17 for current, entering in nodes:
18 node_type = current.t
19 if node_type in ("html_inline", "html_block", "text"):
20 context.on_text(current.literal.replace("\n", " "), node_type)
21 elif node_type == "linebreak":
22 if entering:
23 context.on_text("\n", node_type)
24 elif node_type == "softbreak":
25 if entering:
26 context.on_text(" ", node_type)
27 elif node_type == "link":
28 if entering:
29 link_style = console.get_style("markdown.link", default="none")
30 if self.hyperlinks:
31 link_style += Style(link=current.destination)
32 context.enter_style(link_style)
33 else:
34 context.leave_style()
35 if not self.hyperlinks:
36 context.on_text(" (", node_type)
37 style = Style(underline=True) + console.get_style(
38 "markdown.link_url", default="none"
39 )
40 context.enter_style(style)
41 context.on_text(current.destination, node_type)
42 context.leave_style()
43 context.on_text(")", node_type)
44 elif node_type in inlines:
45 if current.is_container():
46 if entering:
47 context.enter_style(f"markdown.{node_type}")
48 else:
49 context.leave_style()
50 else:
51 context.enter_style(f"markdown.{node_type}")
52 if current.literal:
53 context.on_text(current.literal, node_type)
54 context.leave_style()
55 else:
56 element_class = self.elements.get(node_type) or UnknownElement
57 if current.is_container():
58 if entering:
59 element = element_class.create(self, current)
60 context.stack.push(element)
61 element.on_enter(context)
62 else:
63 element = context.stack.pop()
64 if context.stack:
65 if context.stack.top.on_child_close(context, element):
66 if new_line:
67 yield Segment("\n")
68 yield from console.render(element, context.options)
69 element.on_leave(context)
70 else:
71 element.on_leave(context)
72 else:
73 element.on_leave(context)
74 yield from console.render(element, context.options)
75 new_line = element.new_line
76 else:
77 element = element_class.create(self, current)
78
79 context.stack.push(element)
80 element.on_enter(context)
81 if current.literal:
82 element.on_text(context, current.literal.rstrip())
83 context.stack.pop()
84 if context.stack.top.on_child_close(context, element):
85 if new_line:
86 yield Segment("\n")
87 yield from console.render(element, context.options)
88 element.on_leave(context)
89 else:
90 element.on_leave(context)
91 new_line = element.new_line
Path 3: 1 calls (0.25)
Console (1)
ConsoleOptions (1)
Segment (7)
StopIteration (1)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 """Render markdown to the console."""
5 style = console.get_style(self.style, default="none")
6 options = options.update(height=None)
7 context = MarkdownContext(
8 console,
9 options,
10 style,
11 inline_code_lexer=self.inline_code_lexer,
12 inline_code_theme=self.inline_code_theme,
13 )
14 nodes = self.parsed.walker()
15 inlines = self.inlines
16 new_line = False
17 for current, entering in nodes:
18 node_type = current.t
19 if node_type in ("html_inline", "html_block", "text"):
20 context.on_text(current.literal.replace("\n", " "), node_type)
21 elif node_type == "linebreak":
22 if entering:
23 context.on_text("\n", node_type)
24 elif node_type == "softbreak":
25 if entering:
26 context.on_text(" ", node_type)
27 elif node_type == "link":
28 if entering:
29 link_style = console.get_style("markdown.link", default="none")
30 if self.hyperlinks:
31 link_style += Style(link=current.destination)
32 context.enter_style(link_style)
33 else:
34 context.leave_style()
35 if not self.hyperlinks:
36 context.on_text(" (", node_type)
37 style = Style(underline=True) + console.get_style(
38 "markdown.link_url", default="none"
39 )
40 context.enter_style(style)
41 context.on_text(current.destination, node_type)
42 context.leave_style()
43 context.on_text(")", node_type)
44 elif node_type in inlines:
45 if current.is_container():
46 if entering:
47 context.enter_style(f"markdown.{node_type}")
48 else:
49 context.leave_style()
50 else:
51 context.enter_style(f"markdown.{node_type}")
52 if current.literal:
53 context.on_text(current.literal, node_type)
54 context.leave_style()
55 else:
56 element_class = self.elements.get(node_type) or UnknownElement
57 if current.is_container():
58 if entering:
59 element = element_class.create(self, current)
60 context.stack.push(element)
61 element.on_enter(context)
62 else:
63 element = context.stack.pop()
64 if context.stack:
65 if context.stack.top.on_child_close(context, element):
66 if new_line:
67 yield Segment("\n")
68 yield from console.render(element, context.options)
69 element.on_leave(context)
70 else:
71 element.on_leave(context)
72 else:
73 element.on_leave(context)
74 yield from console.render(element, context.options)
75 new_line = element.new_line
76 else:
77 element = element_class.create(self, current)
78
79 context.stack.push(element)
80 element.on_enter(context)
81 if current.literal:
82 element.on_text(context, current.literal.rstrip())
83 context.stack.pop()
84 if context.stack.top.on_child_close(context, element):
85 if new_line:
86 yield Segment("\n")
87 yield from console.render(element, context.options)
88 element.on_leave(context)
89 else:
90 element.on_leave(context)
91 new_line = element.new_line
Path 4: 1 calls (0.25)
Console (1)
ConsoleOptions (1)
Segment (139)
StopIteration (1)
1def __rich_console__(
2 self, console: Console, options: ConsoleOptions
3 ) -> RenderResult:
4 """Render markdown to the console."""
5 style = console.get_style(self.style, default="none")
6 options = options.update(height=None)
7 context = MarkdownContext(
8 console,
9 options,
10 style,
11 inline_code_lexer=self.inline_code_lexer,
12 inline_code_theme=self.inline_code_theme,
13 )
14 nodes = self.parsed.walker()
15 inlines = self.inlines
16 new_line = False
17 for current, entering in nodes:
18 node_type = current.t
19 if node_type in ("html_inline", "html_block", "text"):
20 context.on_text(current.literal.replace("\n", " "), node_type)
21 elif node_type == "linebreak":
22 if entering:
23 context.on_text("\n", node_type)
24 elif node_type == "softbreak":
25 if entering:
26 context.on_text(" ", node_type)
27 elif node_type == "link":
28 if entering:
29 link_style = console.get_style("markdown.link", default="none")
30 if self.hyperlinks:
31 link_style += Style(link=current.destination)
32 context.enter_style(link_style)
33 else:
34 context.leave_style()
35 if not self.hyperlinks:
36 context.on_text(" (", node_type)
37 style = Style(underline=True) + console.get_style(
38 "markdown.link_url", default="none"
39 )
40 context.enter_style(style)
41 context.on_text(current.destination, node_type)
42 context.leave_style()
43 context.on_text(")", node_type)
44 elif node_type in inlines:
45 if current.is_container():
46 if entering:
47 context.enter_style(f"markdown.{node_type}")
48 else:
49 context.leave_style()
50 else:
51 context.enter_style(f"markdown.{node_type}")
52 if current.literal:
53 context.on_text(current.literal, node_type)
54 context.leave_style()
55 else:
56 element_class = self.elements.get(node_type) or UnknownElement
57 if current.is_container():
58 if entering:
59 element = element_class.create(self, current)
60 context.stack.push(element)
61 element.on_enter(context)
62 else:
63 element = context.stack.pop()
64 if context.stack:
65 if context.stack.top.on_child_close(context, element):
66 if new_line:
67 yield Segment("\n")
68 yield from console.render(element, context.options)
69 element.on_leave(context)
70 else:
71 element.on_leave(context)
72 else:
73 element.on_leave(context)
74 yield from console.render(element, context.options)
75 new_line = element.new_line
76 else:
77 element = element_class.create(self, current)
78
79 context.stack.push(element)
80 element.on_enter(context)
81 if current.literal:
82 element.on_text(context, current.literal.rstrip())
83 context.stack.pop()
84 if context.stack.top.on_child_close(context, element):
85 if new_line:
86 yield Segment("\n")
87 yield from console.render(element, context.options)
88 element.on_leave(context)
89 else:
90 element.on_leave(context)
91 new_line = element.new_line