Skip to content

Escape plain text description hover correctly#283

Merged
aeschli merged 6 commits intomicrosoft:mainfrom
Legend-Master:escape-plain-text-hover
Nov 3, 2025
Merged

Escape plain text description hover correctly#283
aeschli merged 6 commits intomicrosoft:mainfrom
Legend-Master:escape-plain-text-hover

Conversation

@Legend-Master
Copy link
Contributor

This matches the behavior with the documentation shown in the autocomplete

With this schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "test": {
      "description": "For example:\n\n<script>\n  alert(1)\n</script>\n\n    Test [1]"
    }
  }
}

Before:

image

After:

image

@aeschli
Copy link
Collaborator

aeschli commented Sep 29, 2025

The reformatting makes it hard to discover what the fix is. Can you explain?

Copy link
Contributor Author

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry about the formatting/refactor, so I started with the block above and did some clean ups as I read them but then I realized that the problem is more at the toMarkdown function, the main fixes should be in there

Comment on lines +116 to +120
return plain
.trim()
.replace(/[\\`*_{}[\]()<>#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
.replace(/([ \t]+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape spaces tabs
.replace(/\n/g, '\\\n'); // escape new lines
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix

enumValue = JSON.stringify(enumValue);
}
}
if (!schema) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize the change created such a big diff, the main change here is just an early return, and a for of instead of every

@aeschli aeschli enabled auto-merge (squash) September 29, 2025 16:13
aeschli
aeschli previously approved these changes Sep 29, 2025
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 29, 2025
@aeschli aeschli modified the milestones: September 2025, October 2025 Sep 29, 2025
@aeschli
Copy link
Collaborator

aeschli commented Sep 29, 2025

Test failure...

auto-merge was automatically disabled September 30, 2025 02:53

Head branch was pushed to by a user without write access

@Legend-Master
Copy link
Contributor Author

Test failure...

Should be fixed now

Removed `MarkedString.fromPlainText` as that escapes the input
and is not what we want here
(we use `toMarkdown` which isn't the same)
@aeschli aeschli merged commit fb83547 into microsoft:main Nov 3, 2025
3 checks passed
@leia-uwu
Copy link

leia-uwu commented Feb 1, 2026

why are spaces being replaced with non line breaking spaces (&nbsp;) ?

this makes text wrapping on long tooltips worse
on vscode for example it will break in the middle of words and even insert spaces as the first character of new lines, and in some other editors like kate it will prevent wrapping at all and add a horizontal scrollbar

@Legend-Master
Copy link
Contributor Author

Legend-Master commented Feb 2, 2026

It is used to preserve consecutive spaces, text wrappings are definitely a problem though, maybe we could use pre tag here instead?

Edit: pre tag doesn't seem to work here

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

Successfully merging this pull request may close these issues.

4 participants