Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] How to override markdown header justification? #2137

Closed
philwareublox opened this issue Mar 31, 2022 · 6 comments
Closed

[QUESTION] How to override markdown header justification? #2137

philwareublox opened this issue Mar 31, 2022 · 6 comments

Comments

@philwareublox
Copy link

Hello,
Can I override the classes inside the markdown module?
I'd like to change the Heading class, specifically I'd like to override the text.justify = "center" in the markdown Heading class.
How can I do this?

Many thanks,
Phil.

@willmcgugan
Copy link
Collaborator

It's not documented, but the Markdown class is easy to extend. There is a classvar called elements, which maps a markdown block on a class. You can use this to replace the Heading class with your own custom version.

@github-actions
Copy link

github-actions bot commented Apr 1, 2022

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

@philwareublox
Copy link
Author

Thanks for the tip.
I simply created a new class myHeader(TextElement): with my own style and replaced the default one by:

Markdown.elements['heading'] = myHeading

@ssbarnea
Copy link
Contributor

To be honest, I do find the default decision to center bit weird as almost everyone working with markdown does not do centered titles. Look at Google Docs, Git markdown, all of them indent to left, even on generic webpage documents title is not centered by default and most authors do not opt-in for picking centered. There are reasons related to readability that made most switch to this, as 100 years ago centering was standard.

When it comes to terminal, centering is even more damaging to readability, so how about considering now centering by default? WDYT? How about opening a poll on discussions about the subject?

@willmcgugan
Copy link
Collaborator

Headers are typically rendered larger than the body text in HTML. You can't do that in the terminal. If headers were all aligned to the left they would be indistinguishable from body text, even with bold / underline.

Centered headings are perfectly readable.

@hek2mgl
Copy link

hek2mgl commented May 31, 2024

I'm using python -m rich.markdown in a shell script. When possible, I would like to avoid extending the Python class and keep using the vanilla version of rich.

The result looks great! I only admit that I'm also thinking that the centered headlines are breaking the flow of text a bit for me.

@willmcgugan you made a good point that there is no option to render the headers larger than the body at the terminal and therefore the options are somewhat limited. This makes sense! I still gave it a try, and and for my current use case, <=3 level of hierarchy, justify = "left" for the headers looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants