Skip to content

Markdown code blocks get removed from hover #1023

@Robotino04

Description

@Robotino04

Some part of the markdown renderer used for lsp hovers strips out code blocks that use triple backticks (```). Single backticks are not affected.

This reproduces on the clangd demo, the Application Playground demo (the typescript part), but notably not the TypeScript one.
Maybe the layout has an impact as the first two both use ViewsService, but TypeScript uses EditorService. That is just speculation though.

More details using clangd as an example (because it logs its messages):

When hovering over printf, clangd sends this:

{
  "id": 7,
  "jsonrpc": "2.0",
  "result": {
    "contents": {
      "kind": "markdown",
      "value": "### function `printf`  \nprovided by `<stdio.h>`  \n\n---\n→ `int`  \nParameters:  \n- `const char *__restrict`\n\n---\n```cpp\nint printf(const char *__restrict, ...)\n```"
    },
    "range": {
      "end": { "character": 7, "line": 4 },
      "start": { "character": 1, "line": 4 }
    }
  }
}

That is, this markdown:

### function `printf`  
provided by `<stdio.h>`  

---
→ `int`  
Parameters:  
- `const char *__restrict`

---
```cpp
int printf(const char *__restrict, ...)
```

However, it doesn't render the last part (this looks like it can be scrolled, but it can't):

Image

The html that gets generated looks like this:

<div class="rendered-markdown">
    <h3>function <code>printf</code></h3>
    <p>provided by <code>&lt;stdio.h&gt;</code> </p>
    <hr>
    <p><code>int</code><br>Parameters: </p>
    <ul>
        <li><code>const char *__restrict</code></li>
    </ul>
    <hr>
    <div data-code="id#3"><span></span></div>
</div>

The code block got turned into the <div data-code="id#3"><span></span></div> part.

The markdown itself gets passed along all the way to the function that updates the DOM, but the renderer just creates wrong html somewhere in the middle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions