-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Vertical size limit for code blocks #3444
Comments
While there is no configuration option that allows you to limit the height, you could achieve a fixed height with a bit of custom css: # mkdocs.yml
extra_css: custom-styles.css /* custom-styles.css */
.md-typeset pre > code {
max-height: 5rem;
} If you need more specifity for your css selector you could add a custom class to your code block(s) using the extension attr_list. |
Thanks @lampensau - great customization! It’s trivial to add with CSS. Edit: my explanation might be a bit brief (was answering on mobile), so here's an attempt to explain my thinking: we could, in theory, add a ``` { .py style="--md-codeblock-height: 200px" }
...
``` .md-typeset pre > code {
max-height: var(--md-codeblock-height, 5rem); /* 5rem will be used as a fallback value */
} |
Nice, thanks to you both ! I'll use this solution |
Hi. here is my mkdocs.yaml
Here is snip off my code block```
|
Contribution guidelines
I want to suggest an idea and checked that ...
Description
It would be very useful to have an optional
max-nb-lines
property on code blocks allowing to limit the number of lines actually displayed, letting users scroll down if they need to see the rest.Use Cases
In mkdocs-gallery I try to reproduce what is provided in sphinx-gallery but using
mkdocs
instead ofsphinx
. For this I am leveraging as much as possiblemkdocs-material
so that example scripts are transformed into markdown source documents with as little as possible raw html (separation of concerns).There is one feature of sphinx-gallery for which it does not seem possible with mkdocs-material code blocks as of today: the ability to limit displayed line numbers. This capability is demonstrated in
Is there an obvious trick that I would have missed ? In which case I would be happy to propose a documentation PR so that other users find it easily too. Otherwise, could this be a feature for a future version ? Maybe obtained by setting an
max-nb-lines
attribute on the code block.For reference, the associated issue in mkdocs-gallery is smarie/mkdocs-gallery#7
Note: issue #2171 seems related but only talks about width if I am not mistaken.
Screenshots / Mockups
The text was updated successfully, but these errors were encountered: