question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Display a table in diagnostic window of Monaco Editor

See original GitHub issue

Context

  • This issue is not a bug report. (please use a different template for reporting a bug)
  • This issue is not a duplicate of an existing issue. (please use the search to find existing issues)

Description

(* I don’t know if it is an existing feature or not *)

In this sample of Monaco Editor, when we hover on the Hover over this text, we could see markdown result in the diagnostic window. The contents of the window are provided by the code:

	contents: [
	    { value: '**SOURCE**' },
		{ value: '```html\n' + res.responseText.substring(0, 200) + '\n```' }
	]

I’m wondering if it is possible to draw a table in the diagnostic window.

enter image description here

I tried to add { value: '| a | b | c | d | e | |---|---|---|---|---| | 1 | 2 | 3 | 4 | 5 |'}, it did not work.

Could anyone help?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
spahnkecommented, Dec 27, 2021

You can use a template string for that (the line breaks are important for the table rendering).

CSS (augmented from post above):

.monaco .hover-content table, th, td {
    border: 1px solid black;
}

Hover element:

contents: [
    { value: '**SOURCE**' },
    { value: `
| a | b | c | d | e |
|---|---|---|---|---|
| f | g | h | i | j |` 
    }
]
3reactions
rcjsuencommented, Dec 27, 2021

I tried to add { value: '| a | b | c | d | e | |---|---|---|---|---| | 1 | 2 | 3 | 4 | 5 |'}, it did not work.

@chengtie You can achieve this with raw HTML and specifying supportHtml. You may also be interested in #801.

image

table, th, td {
  border: 1px solid black;
}
monaco.languages.register({ id: 'mySpecialLanguage' });

monaco.languages.registerHoverProvider('mySpecialLanguage', {
    provideHover: function (model) {
        return {
            range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
            contents: [
                {
                    value: "<table><tr><td>abc</td><td>123</td></tr><tr><td>abc</td><td>123</td></tr></table>",
                    supportHtml: true
                },
            ]
        }
    }
});

monaco.editor.create(document.getElementById("container"), {
    value: '\n\nHover over this text',
    language: 'mySpecialLanguage'
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Display a table in diagnostic window of Monaco Editor
I'm wondering if it is possible to draw a table in the diagnostic window. enter image description here. I tried to add {...
Read more >
HTML support in hover (inline HTML in IMarkdownString) #801
I did some experimenting and was able to achieve this via commands inside the IMarkdownString . I couldn't get this to work in...
Read more >
Monaco Editor Playground
The Monaco Editor can be easily created, given an // empty container and an options literal. // Two members of the literal are...
Read more >
monaco-editor | Yarn - Package Manager
The Monaco Editor is the code editor which powers VS Code, with the features better described here. Please note that this repository contains...
Read more >
Matrix Table Question - Qualtrics
Carousel View. Carousel view allows survey takers to view matrix tables one statement at a time. In the editor, these look the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found