Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize the JSON schema hover?

Using monaco-editor v0.14.3, we have set up a JSON editor, based on a JSON schema, like this:

monaco.languages.json.jsonDefaults.setDiagnosticsOptions(
{
  validate: true,
  allowComments: true,
  schemas:
    [
      {
        uri: "https://server/schema.json",
        fileMatch: ["*.json"],
        schema: schema
      }]
});

where schema is a JSON schema object, for which the description property is defined for every property in the schema. This description property contains some HTML tags, and when hovering the JSON editor, this description is shown without interpreting the HTML tags, which displays something like "This property <b>defines</b> the way…".

We have looked in the direction of the monaco.languages.registerHoverProvider() method, in order to provide the hover text ourselves, but cannot access to the default hover mechanism, which computes the default JSON schema property, so as to customize it and turn the HTML into Markdown: is it possible to access to the description in the JSON schema related to the hovered text?

In addition, when modifying the JSON schema description property by using Markdown or HTML, the built-in hovering keeps on interpreting this field as raw text: is it possible to force the default hovering system to interpret in as Markdown or HTML?

like image 531
Édouard Mercier Avatar asked Mar 26 '26 01:03

Édouard Mercier


1 Answers

Thanks to the guys from Monaco, there is an undocumented property named markdownDescription which the JSON language service uses instead of the description. This isn't standard, but it works.

like image 98
user5365075 Avatar answered Mar 27 '26 23:03

user5365075



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!