File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 11import os
2- from typing import Optional
2+ from typing import TYPE_CHECKING , Optional
33
4- from rich .console import Console
4+ from rich .console import Console , RenderResult
5+ from rich .markdown import Heading , Markdown
6+ from rich .text import Text
7+
8+ if TYPE_CHECKING :
9+ from rich .console import ConsoleOptions
510
611console_out = Console ()
712console_err = Console (stderr = True )
@@ -45,3 +50,20 @@ def is_dark_console() -> Optional[bool]:
4550
4651# when we could not detect it, use dark theme as most terminals are dark
4752_SYNTAX_HIGHLIGHT_THEME = _SYNTAX_HIGHLIGHT_LIGHT_THEME if is_dark_console () is False else _SYNTAX_HIGHLIGHT_DARK_THEME
53+
54+
55+ class CycodeHeading (Heading ):
56+ """Custom Rich Heading for Markdown.
57+
58+ Changes:
59+ - remove justify to 'center'
60+ - remove the box for h1
61+ """
62+
63+ def __rich_console__ (self , console : 'Console' , options : 'ConsoleOptions' ) -> RenderResult :
64+ if self .tag == 'h2' :
65+ yield Text ('' )
66+ yield self .text
67+
68+
69+ Markdown .elements ['heading_open' ] = CycodeHeading
You can’t perform that action at this time.
0 commit comments