You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are using Rich for logging (from rich.logging import RichHandler), and I have a few questions about its text formatting in Jupyter notebooks. First, it seems to be adding a large spacing between lines.
Looking at the HTML source code, Jupyter seems to be adding a margin-bottom to the child elements of .jp-RenderedHTMLCommon (in this case, each line is a single pre element inside the wrapper, so the .jp-RenderedHTMLCommon > *:last-child { margin-bottom: 0.5em } takes effect. I'm not sure if we have control over Jupyter CSS, but it seems like overriding the style of the pre element set in JUPYTER_HTML_FORMAT helps to remove the vertical spacing:
rich.jupyter.JUPYTER_HTML_FORMAT="""\<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace;margin-bottom:0px">{code}</pre>"""
Let me know if that makes sense. Since users can override JUPYTER_HTML_FORMAT, there is no urgency in changing it in the code or making it explicitly user-configurable. But it probably would be nice to hardcode margin-bottom:0px there.
There is still an issue remaining with the widgets though. In my example, the searching line is not printed by the logging's RichHandler, but rather it's an instance of rich.progress.Progress. So in this case, the pre element is additionally wrapped in a .jupyter-widgets div that has { margin: var(--jp-widgets-margin) }, which adds an additional margin-left, making the progress bar unaligned with the log prints vertically. I wonder if you have ideas on how to fix that as well?
The text was updated successfully, but these errors were encountered:
Hi!
We are using Rich for logging (
from rich.logging import RichHandler
), and I have a few questions about its text formatting in Jupyter notebooks. First, it seems to be adding a large spacing between lines.Notebook output:
With especially large spacing after the progress bar widget.
Compared that to a standard text output:
Looking at the HTML source code, Jupyter seems to be adding a margin-bottom to the child elements of
.jp-RenderedHTMLCommon
(in this case, each line is a singlepre
element inside the wrapper, so the.jp-RenderedHTMLCommon > *:last-child { margin-bottom: 0.5em }
takes effect. I'm not sure if we have control over Jupyter CSS, but it seems like overriding the style of thepre
element set inJUPYTER_HTML_FORMAT
helps to remove the vertical spacing:Let me know if that makes sense. Since users can override
JUPYTER_HTML_FORMAT
, there is no urgency in changing it in the code or making it explicitly user-configurable. But it probably would be nice to hardcodemargin-bottom:0px
there.There is still an issue remaining with the widgets though. In my example, the
searching
line is not printed by the logging's RichHandler, but rather it's an instance ofrich.progress.Progress
. So in this case, thepre
element is additionally wrapped in a.jupyter-widgets
div that has{ margin: var(--jp-widgets-margin) }
, which adds an additional margin-left, making the progress bar unaligned with the log prints vertically. I wonder if you have ideas on how to fix that as well?The text was updated successfully, but these errors were encountered: