Skip to content

Instantly share code, notes, and snippets.

@Hultner
Last active June 4, 2020 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hultner/75a0308aa8dcdeb56ba1139acf3d18db to your computer and use it in GitHub Desktop.
Save Hultner/75a0308aa8dcdeb56ba1139acf3d18db to your computer and use it in GitHub Desktop.
Rich subtle markdown style
from typing import Any
from rich.console import Console, ConsoleOptions, RenderResult
from rich.markdown import Markdown, Heading, Text
class SubtleHeading(Heading):
def __init__(self, level):
# Defering all headings by one level to avoid the borderd box for H1, hence level 2 is max
super().__init__(level + 1)
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
# Overwriting this to avoid the center-alginment
# h1 is unused since we defer all levels by one level
text = self.text
# Styled text for h2 and beyond
if self.level == 2:
yield Text("\n")
yield text
class SubtleMarkdown(Markdown):
def __init__(self, *args, **kwargs):
super(SubtleMarkdown, self).__init__(*args, **kwargs)
self.elements["heading"] = SubtleHeading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment