monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] monaco.editor.colorize does not work as expected with json language

Open Ruminat opened this issue 2 years ago • 3 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Code

I don't know how to reproduce this issue in VS Code Desktop

How to reproduce the bug

Go to playground: https://microsoft.github.io/monaco-editor/playground.html#creating-the-editor-syntax-highlighting-for-html-elements

Replace the code in the JavaScript tab with this:

const jsonCode = `{ "some": "body once told me" }`;
const language = "json";
monaco.editor.colorize(jsonCode, language, { tabSize: 2 }).then((code) => {
    document.getElementById('code').innerHTML = code;
    console.log(code)
});

Actual Behavior

no syntax highlighting for JSON — this is the output I get (HTML): <span><span class="mtk1">{ "some": "body once told me" }</span></span><br/>

Expected Behavior

syntax highlighted JSON output

Additional Context

If you change const language = "json"; to const language = "javascript"; it works though, it gives the expected output: <span><span class="mtk1">{ </span><span class="mtk20">"some"</span><span class="mtk1">: </span><span class="mtk20">"body once told me"</span><span class="mtk1"> }</span></span><br/>

Ruminat avatar May 16 '22 11:05 Ruminat

I encounter the same issue with monaco.editor.colorizeElement, reproducible in the Monaco Editor playground.

How to reproduce the bug

Playground https://microsoft.github.io/monaco-editor/playground.html#creating-the-editor-syntax-highlighting-for-html-elements

Leave Javascript as default:

monaco.editor.colorizeElement(document.getElementById('code'));

Set HTML as:

<pre id="code" data-lang="json" style="width: 500px">
{
    "boolean": true,
    "string": "test",
    "int": 10
}
</pre>

Actual Behavior

Resulted HTML (formatted):

<pre id="code" data-lang="json" style="width: 500px;" class="vs">
    <span>
        <span class="mtk1">{</span>
    </span>
    <br />
    <span>
        <span class="mtk1">&nbsp;&nbsp;&nbsp;&nbsp;"boolean":&nbsp;true,</span>
    </span>
    <br />
    <span>
        <span class="mtk1">&nbsp;&nbsp;&nbsp;&nbsp;"string":&nbsp;"test",</span>
    </span>
    <br />
    <span>
        <span class="mtk1">&nbsp;&nbsp;&nbsp;&nbsp;"int":&nbsp;10</span>
    </span>
    <br />
    <span>
        <span class="mtk1">}</span>
    </span>
    <br />
    <span>
        <span></span>
    </span>
    <br />
</pre>

.mtk1 class has only color: #000000;

Screenshot: az

Expected Behavior

Syntax highlighted JSON output

Skkay avatar Jun 05 '22 09:06 Skkay

I'm having the same issue, for some reason a delay after onMount fixes this issue for me. Not sure why:D

Code42Cate avatar Jul 06 '22 15:07 Code42Cate

I can verify, but I have no idea what causes this.

hediet avatar Jul 19 '22 12:07 hediet

Did anyone find a solution or a workaround for this issue?

yairsimantov20 avatar Dec 16 '22 08:12 yairsimantov20

I have the same problem... It would be nice to fix it.

3da avatar May 10 '23 12:05 3da

I'm also running into the same issue. Are there any updates on this, @alexdima?

AGao00 avatar Nov 01 '23 22:11 AGao00