Repository navigation
feat: expose the CSS and HTML language workers - #18
Merged
Merged
Conversation
Monaco has public getters for its TypeScript and JSON workers but not for CSS and HTML, so editor code can't use those language services for content embedded in another language, e.g. a <style> block in an HTML or Vue template. node-red/node-red#5994 uses this for CSS completion, hover and colours. - monaco.css.getWorker(languageId = "css") for css, scss and less - monaco.html.getWorker(languageId = "html") for html, handlebars, razor and languages added with registerHTMLLanguageService() - Same shape as monaco.json.getWorker(): resolves to (...uris) => Promise<worker>, rejects until the language has been used - Applied in generate-monaco-esm-i18n.js; the build fails if a patch no longer matches, so a Monaco update can't drop it silently - Browser test for both getters
This was referenced Oct 11, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #9 and node-red/node-red#5994
Summary
The main reason for this is working towards Vue and Vuetify support in Dashboard 2 (see #9 and https://discourse.nodered.org/t/weather-card-struggling-with-methods/85434/6?u=steve-mcl).
node-red/node-red#5994 adds JavaScript and CSS support to
<script>and<style>blocks in Node-RED's HTML editors, which Dashboard 2's ui-template builds on. The JavaScript side usesmonaco.typescript.getJavaScriptWorker(), which Monaco already exposes. There is no equivalent for CSS or HTML: Monaco has public worker getters for TypeScript and JSON (monaco.json.getWorker()) but not for CSS and HTML. So #5994 can only show CSS errors, not completion, hover or colour previews.This adds the two missing getters, with the same shape as
monaco.json.getWorker():monaco.css.getWorker(languageId = "css")forcss,scssandlessmonaco.html.getWorker(languageId = "html")forhtml,handlebars,razor, and any language added withmonaco.html.registerHTMLLanguageService()Each resolves to
(...uris) => Promise<worker>and rejects with"<languageId> not registered!"until that language has been used, because its worker starts lazily.Changes
generate-monaco-esm-i18n.js: newexposeLanguageWorkers()step after the copy. It patchescssMode.js/htmlMode.jsso each language keeps its worker accessor, exportsgetWorkerfromregister.js, and re-exports it from the oldervs/language/{css,html}/monaco.contribution.jspath.replace-in-filecounts matches withString.match(), so a non-global regex reports its capture groups as matches.patchExactly()makes the regex global before counting.test/browser/editor.test.js: new test. The API is present; an unused language rejects; CSSdoCompleteandfindDocumentColors; SCSSdoHover; HTMLdoComplete; and a language added withregisterHTMLLanguageService(). It has its own timeout, because a worker that fails to start makes its calls wait forever.README.md: a note under Notes.Testing
npm run build: the patch applies cleanly against Monaco 0.57.0.editor.jsgrows by 720 bytes (4,985,273 to 4,985,993); the workers are unchanged.npm test81/81,test:buildoutput tier 85/85,test:browser7/7 (6 before, plus the new one).<style>support, no console errors.Notes
test.ymlonly runs for PRs intomainandmonaco-0.57.0. I can add a commit to include this PR's base, or we can just wait until it's rebased ontomain.registerHTMLLanguageService()asksMonacoEnvironment.getWorkerUrlfor a worker labelled with its own id. The test maps that label tohtml, which is what feat: add JavaScript and CSS support to script and style blocks in HT… node-red#5994 now does in Node-RED'sgetWorkerUrl.