From b923d63700da2422376a0f38e3f4c8f70b3a643f Mon Sep 17 00:00:00 2001 From: "Peter Schilling (aider)" Date: Thu, 27 Mar 2025 13:48:12 -0700 Subject: [PATCH 1/4] aider: style: Left-align markdown headings --- aider/mdstream.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/aider/mdstream.py b/aider/mdstream.py index c38f84ce7..53771c8cb 100755 --- a/aider/mdstream.py +++ b/aider/mdstream.py @@ -5,7 +5,7 @@ import time from rich.console import Console from rich.live import Live -from rich.markdown import CodeBlock, Markdown +from rich.markdown import CodeBlock, Heading, Markdown from rich.syntax import Syntax from rich.text import Text @@ -56,13 +56,28 @@ class NoInsetCodeBlock(CodeBlock): yield syntax +class LeftHeading(Heading): + """A heading class that renders left-justified.""" + + def __rich_console__(self, console, options): + text = self.text + text.justify = "left" # Override justification + yield text + + class NoInsetMarkdown(Markdown): - """Markdown with code blocks that have no padding.""" + """Markdown with code blocks that have no padding and left-justified headings.""" elements = { **Markdown.elements, "fence": NoInsetCodeBlock, "code_block": NoInsetCodeBlock, + "heading1": LeftHeading, + "heading2": LeftHeading, + "heading3": LeftHeading, + "heading4": LeftHeading, + "heading5": LeftHeading, + "heading6": LeftHeading, } From 779f07f0721c43cbfe3af4c963f36f293e91ef8d Mon Sep 17 00:00:00 2001 From: "Peter Schilling (aider)" Date: Thu, 27 Mar 2025 13:58:05 -0700 Subject: [PATCH 2/4] aider: fix: Align headings left while preserving h1/h2 styling --- aider/mdstream.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/aider/mdstream.py b/aider/mdstream.py index 53771c8cb..131f732a1 100755 --- a/aider/mdstream.py +++ b/aider/mdstream.py @@ -3,9 +3,11 @@ import io import time +from rich import box from rich.console import Console from rich.live import Live from rich.markdown import CodeBlock, Heading, Markdown +from rich.panel import Panel from rich.syntax import Syntax from rich.text import Text @@ -62,7 +64,18 @@ class LeftHeading(Heading): def __rich_console__(self, console, options): text = self.text text.justify = "left" # Override justification - yield text + if self.tag == "h1": + # Draw a border around h1s, but keep text left-aligned + yield Panel( + text, + box=box.HEAVY, + style="markdown.h1.border", + ) + else: + # Styled text for h2 and beyond + if self.tag == "h2": + yield Text("") # Keep the blank line before h2 + yield text class NoInsetMarkdown(Markdown): From 13b62e3d064d6b8b4859f40febf69f9ef0c2f7d4 Mon Sep 17 00:00:00 2001 From: "Peter Schilling (aider)" Date: Thu, 27 Mar 2025 13:59:58 -0700 Subject: [PATCH 3/4] aider: fix: Use correct token type for markdown heading alignment --- aider/mdstream.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/aider/mdstream.py b/aider/mdstream.py index 131f732a1..47021115b 100755 --- a/aider/mdstream.py +++ b/aider/mdstream.py @@ -85,12 +85,7 @@ class NoInsetMarkdown(Markdown): **Markdown.elements, "fence": NoInsetCodeBlock, "code_block": NoInsetCodeBlock, - "heading1": LeftHeading, - "heading2": LeftHeading, - "heading3": LeftHeading, - "heading4": LeftHeading, - "heading5": LeftHeading, - "heading6": LeftHeading, + "heading_open": LeftHeading, # Use the correct token type key } From d5cec5f71ee523ce73f044f17cd2d18ecdad8f17 Mon Sep 17 00:00:00 2001 From: "Peter Schilling (aider)" Date: Thu, 27 Mar 2025 14:08:04 -0700 Subject: [PATCH 4/4] aider: chore: Remove unnecessary comment in mdstream.py --- aider/mdstream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/mdstream.py b/aider/mdstream.py index 47021115b..24c14f0d4 100755 --- a/aider/mdstream.py +++ b/aider/mdstream.py @@ -85,7 +85,7 @@ class NoInsetMarkdown(Markdown): **Markdown.elements, "fence": NoInsetCodeBlock, "code_block": NoInsetCodeBlock, - "heading_open": LeftHeading, # Use the correct token type key + "heading_open": LeftHeading, }