mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 12:45:00 +00:00
refactor: extract markdown rendering logic into helper method
This commit is contained in:
parent
8e64f171b8
commit
684fdb6095
1 changed files with 20 additions and 11 deletions
|
@ -70,6 +70,25 @@ class MarkdownStream:
|
||||||
self.live = Live(Text(""), refresh_per_second=1.0 / self.min_delay)
|
self.live = Live(Text(""), refresh_per_second=1.0 / self.min_delay)
|
||||||
self.live.start()
|
self.live.start()
|
||||||
|
|
||||||
|
def _render_markdown_to_lines(self, text):
|
||||||
|
"""Render markdown text to a list of lines.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text (str): Markdown text to render
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: List of rendered lines with line endings preserved
|
||||||
|
"""
|
||||||
|
# Render the markdown to a string buffer
|
||||||
|
string_io = io.StringIO()
|
||||||
|
console = Console(file=string_io, force_terminal=True)
|
||||||
|
markdown = Markdown(text, **self.mdargs)
|
||||||
|
console.print(markdown)
|
||||||
|
output = string_io.getvalue()
|
||||||
|
|
||||||
|
# Split rendered output into lines
|
||||||
|
return output.splitlines(keepends=True)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""Destructor to ensure Live display is properly cleaned up."""
|
"""Destructor to ensure Live display is properly cleaned up."""
|
||||||
if self.live:
|
if self.live:
|
||||||
|
@ -101,17 +120,7 @@ class MarkdownStream:
|
||||||
return
|
return
|
||||||
self.when = now
|
self.when = now
|
||||||
|
|
||||||
# ai: refactor this into a helper function...
|
lines = self._render_markdown_to_lines(text)
|
||||||
# Render the markdown to a string buffer
|
|
||||||
string_io = io.StringIO()
|
|
||||||
console = Console(file=string_io, force_terminal=True)
|
|
||||||
markdown = Markdown(text, **self.mdargs)
|
|
||||||
console.print(markdown)
|
|
||||||
output = string_io.getvalue()
|
|
||||||
|
|
||||||
# Split rendered output into lines
|
|
||||||
lines = output.splitlines(keepends=True)
|
|
||||||
# ... ai!
|
|
||||||
|
|
||||||
num_lines = len(lines)
|
num_lines = len(lines)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue