mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
Merge pull request #3662 from schpet/markdown-headings-left
This commit is contained in:
commit
fb23b6c26f
1 changed files with 25 additions and 2 deletions
|
@ -3,9 +3,11 @@
|
||||||
import io
|
import io
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from rich import box
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.live import Live
|
from rich.live import Live
|
||||||
from rich.markdown import CodeBlock, Markdown
|
from rich.markdown import CodeBlock, Heading, Markdown
|
||||||
|
from rich.panel import Panel
|
||||||
from rich.syntax import Syntax
|
from rich.syntax import Syntax
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
|
@ -56,13 +58,34 @@ class NoInsetCodeBlock(CodeBlock):
|
||||||
yield syntax
|
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
|
||||||
|
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):
|
class NoInsetMarkdown(Markdown):
|
||||||
"""Markdown with code blocks that have no padding."""
|
"""Markdown with code blocks that have no padding and left-justified headings."""
|
||||||
|
|
||||||
elements = {
|
elements = {
|
||||||
**Markdown.elements,
|
**Markdown.elements,
|
||||||
"fence": NoInsetCodeBlock,
|
"fence": NoInsetCodeBlock,
|
||||||
"code_block": NoInsetCodeBlock,
|
"code_block": NoInsetCodeBlock,
|
||||||
|
"heading_open": LeftHeading,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue