-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
All <span> tags in hover have a 4px bottom margin which causes nested spans to have stacking bottom margins #232226
Comments
… can override the 4px bottom margin that is added to every span in the Hover
Hover Margin Stacking Issue in VS CodeIssue DescriptionThe current hover implementation in VS Code adds a 4px bottom margin to all Problematic Behavior
Root CauseThe margin is being applied universally through CSS, but the markdown renderer's sanitizer prevents extensions from overriding these margins. This becomes particularly problematic with:
Proposed Fix// markdownRenderer.ts
private static readonly ALLOWED_MARKDOWN_CSS = new Set([
// ... existing allowed styles ...
'margin',
'margin-bottom'
]); And update hover styles: .hover-contents > span { /* Direct children only */
margin-bottom: 4px;
}
.hover-contents span span { /* Nested spans */
margin-bottom: 0;
} This solution:
TestingVerified with the reproduction case in the hover sample extension. No regressions observed in standard hover behaviors. /cc @microsoft/vscode-team |
Hi @aiday-mar, is there anything else you need from me to get my fix for this issue merged? |
Hi @navtej-ac thanks for filing this issue. The change you made touches upon an area which another colleague of mine is responsible for. I assigned him as a reviewer. |
Thank you |
Type: Bug
When an extension provides a hover using the
HoverProvider.provideHover
API, and the hover contains Markdown with HTML in it, every span gets a 4px bottom margin. This was added in #107442 due to microsoft/vscode-pull-request-github#1937This means that nested spans will get stacking margins, and vertically stacked spans will have gaps between them which may be undesirable depending on how the author of the extension wants to style the hover.
Because of the (understandably) restrictive CSS allowed in
markdownRenderer.ts
, we cannot remove this bottom margin.I would consider the stacking margins with nested spans to be a bug, because nested spans may be required to do certain types of styling of text and it does not seem correct for that to cause the margin to expand with each level of nesting.
Demonstration of problem:
To reproduce this:
vscode-extension-samples
repo.margin:0
added to the spans' styling, which causes the HTML sanitizer to strip the stylesExpected: spans with background colors can nest without the outer span increasing in height and spans with backgrounds do not have a vertical gap between them.
Actual: nested spans all have 4px margins which accumulate and vertically stacked spans have a gap between them.
Proposed Fix: Add
margin:0
to the list of allowed styles inmarkdownRenderer.ts
.VS Code version: Code 1.94.2 (Universal) (384ff73, 2024-10-09T16:08:44.566Z)
OS version: Darwin arm64 23.6.0
Modes:
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: