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

[Bug] HTML language does not recognize inline <script type="module"> as JavaScript

Open Yoplitein opened this issue 3 years ago • 11 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

monaco.editor.create(document.getElementById('container'), {
	value: `<script type="module">\n\tconsole.log("hello");\n</script>`,
	language: 'html'
});

Actual Behavior

The contents of the script tag are marked as language vs.editor.nullLanguage, precluding highlighting and, upon editing or merely moving the cursor within the tag, causing various callbacks for editor features to throw Unexpected languageId when calling LanguageConfigurationRegistry.getLanguageConfiguration.

Expected Behavior

Inline code is recognized as JavaScript, is syntax highlighted, and editing/navigation does not raise exceptions.

Additional Context

This began causing exceptions in version 0.32.0, with 0.31.1 and prior nothing is raised but the inline code is still similarly marked as vs.editor.nullMode.

Yoplitein avatar Feb 11 '22 18:02 Yoplitein

I can reproduce. It seems like type="module" tokenizes the content as language module, which does not exist - thus the error. type="html"or type="css" works as expected.

hediet avatar Feb 14 '22 11:02 hediet

Interestingly, type=module (no quotes) works just fine!

image

CetinSert avatar Mar 10 '22 19:03 CetinSert

We fixed this in vscode. The next monaco editor version will be released soon.

hediet avatar Mar 11 '22 13:03 hediet

Seems fixed in 0.33.0, my app works again. You can also close #3090

Prinzhorn avatar Jun 29 '22 18:06 Prinzhorn

0.34.0 has this issue also

<script type="text/javascript">
var qd = {};
</script>

Any click inside script tag produce

image

Delagen avatar Sep 09 '22 08:09 Delagen

Same with Markdown, when annotating a code code block with unknown language:

```mermaid
graph TD;
  A-->B;
  A-->C;
  B-->D;
  C-->D;
```

Error:

errors.ts:21 Uncaught Error: Language id "vs.editor.nullLanguage" is not configured nor known

Error: Language id "vs.editor.nullLanguage" is not configured nor known
    at f (languageConfigurationRegistry.ts:130:10)
    at c.getLanguageConfiguration (languageConfigurationRegistry.ts:113:13)
    at u.getLanguageConfiguration (tokenizationTextModelPart.ts:329:45)
    at u.getWordAtPosition (tokenizationTextModelPart.ts:350:9)
    at Ot.getWordAtPosition (textModel.ts:1860:42)
    at F._getWord (wordHighlighter.ts:355:21)
    at F._run (wordHighlighter.ts:373:21)
    at F._onPositionChanged (wordHighlighter.ts:347:8)
    at wordHighlighter.ts:224:9
    at t.invoke (event.ts:607:17)
    at errors.ts:26:12

(reproduced on the https://microsoft.github.io/monaco-editor playground).

Note that this worked fine on 0.33.0 and broke on 0.34.0.

jonatanklosko avatar Oct 09 '22 19:10 jonatanklosko

  1. reproducible in the monaco editor playground
monaco.editor.create(document.getElementById('container'), {
	value: "```notsupport\nerror when press enter\n```",
	language: 'markdown'
});
  1. solve this problem
+ monaco.languages.register({id: 'vs.editor.nullLanguage'})
+ monaco.languages.setLanguageConfiguration('vs.editor.nullLanguage', {})

monaco.editor.create(document.getElementById('container'), {
	value: "```notsupport\nerror when press enter\n```",
	language: 'markdown'
});

pansinm avatar Nov 03 '22 02:11 pansinm

Error: Language id "vs.editor.nullLanguage" is not configured nor known

This will be fixed with the next release of the monaco editor.

Inline code is recognized as JavaScript, is syntax highlighted,

This is the remaining feature request of this issue.

hediet avatar Feb 07 '23 15:02 hediet

This will be fixed with the next release of the monaco editor.

Was this fix released?

silverwind avatar Apr 17 '24 22:04 silverwind