Themes
Apply editor and syntax colours with an EditorTheme. You need a mounted editor.
With no theme the editor is black text on white with the current line shaded, and its syntax colours follow VS Code’s Light+. A theme sets only the colours you list. Its type picks the defaults for the rest: leave it out or say 'light' for light defaults, or say 'dark' for the dark palette.
1. Set the editor colours
import { Editor } from
'@singapore-editor/cor
e/editor'
import type {
EditorTheme } from
'@singapore-editor/cor
e/rendering'
const theme:
EditorTheme = {
type : 'dark' ,
backgroundColor :
'#18202b' ,
foregroundColor :
'#dce5ef' ,
caretColor :
'#a4d7c2' ,
selectionColor :
'#315066' ,
}
const editor = new
Editor ( document . queryS
elector < HTMLElement >( '
#editor' )!, { theme })
editor . setText ( 'Hello,
theme\n' )
import { Editor } from
'@singapore-editor/cor
e/editor'
import type {
EditorTheme } from
'@singapore-editor/cor
e/rendering'
const theme:
EditorTheme = {
type : 'dark' ,
backgroundColor :
'#18202b' ,
foregroundColor :
'#dce5ef' ,
caretColor :
'#a4d7c2' ,
selectionColor :
'#315066' ,
}
const editor = new
Editor ( document . queryS
elector < HTMLElement >( '
#editor' )!, { theme })
editor . setText ( 'Hello,
theme\n' )
import { Editor } from
'@singapore-editor/core/edit
or'
import type { EditorTheme }
from
'@singapore-editor/core/rend
ering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor :
'#18202b' ,
foregroundColor :
'#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelecto
r < HTMLElement >( '#editor' )!,
{ theme })
editor . setText ( 'Hello,
theme\n' )
import { Editor } from
'@singapore-editor/core/edit
or'
import type { EditorTheme }
from
'@singapore-editor/core/rend
ering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor :
'#18202b' ,
foregroundColor :
'#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelecto
r < HTMLElement >( '#editor' )!,
{ theme })
editor . setText ( 'Hello,
theme\n' )
import { Editor } from
'@singapore-editor/core/editor'
import type { EditorTheme } from
'@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelector < HTMLEl
ement >( '#editor' )!, { theme })
editor . setText ( 'Hello, theme\n' )
import { Editor } from
'@singapore-editor/core/editor'
import type { EditorTheme } from
'@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelector < HTMLEl
ement >( '#editor' )!, { theme })
editor . setText ( 'Hello, theme\n' )
import { Editor } from
'@singapore-editor/core/editor'
import type { EditorTheme } from
'@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor
' )!, { theme })
editor . setText ( 'Hello, theme\n' )
import { Editor } from
'@singapore-editor/core/editor'
import type { EditorTheme } from
'@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor
' )!, { theme })
editor . setText ( 'Hello, theme\n' )
import { Editor } from '@singapore-editor/core/editor'
import type { EditorTheme } from
'@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor' )!, { theme
})
editor . setText ( 'Hello, theme\n' )
import { Editor } from '@singapore-editor/core/editor'
import type { EditorTheme } from
'@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new
Editor ( document . querySelector < HTMLElement >( '#editor' )!, { theme
})
editor . setText ( 'Hello, theme\n' )
import { Editor } from '@singapore-editor/core/editor'
import type { EditorTheme } from '@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
theme })
editor . setText ( 'Hello, theme\n' )
import { Editor } from '@singapore-editor/core/editor'
import type { EditorTheme } from '@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, {
theme })
editor . setText ( 'Hello, theme\n' )
import { Editor } from '@singapore-editor/core/editor'
import type { EditorTheme } from '@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, { theme
})
editor . setText ( 'Hello, theme\n' )
import { Editor } from '@singapore-editor/core/editor'
import type { EditorTheme } from '@singapore-editor/core/rendering'
const theme: EditorTheme = {
type : 'dark' ,
backgroundColor : '#18202b' ,
foregroundColor : '#dce5ef' ,
caretColor : '#a4d7c2' ,
selectionColor : '#315066' ,
}
const editor = new Editor ( document . querySelector < HTMLElement >( '#editor' )!, { theme
})
editor . setText ( 'Hello, theme\n' )
ts example Make live
2. Convert existing VS Code colours
The /shiki entry point converts VS Code theme definitions. It supplies theme colours; language features still come from plugins.
import {
editorThemeFromVscodeT
heme } from
'@singapore-editor/cor
e/shiki'
const theme =
editorThemeFromVscodeT
heme ({
colors : {
'editor.background' :
'#18202b' ,
'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import {
editorThemeFromVscodeT
heme } from
'@singapore-editor/cor
e/shiki'
const theme =
editorThemeFromVscodeT
heme ({
colors : {
'editor.background' :
'#18202b' ,
'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import {
editorThemeFromVscodeTheme }
from
'@singapore-editor/core/shik
i'
const theme =
editorThemeFromVscodeTheme ({
colors : {
'editor.background' :
'#18202b' ,
'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import {
editorThemeFromVscodeTheme }
from
'@singapore-editor/core/shik
i'
const theme =
editorThemeFromVscodeTheme ({
colors : {
'editor.background' :
'#18202b' ,
'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme
} from
'@singapore-editor/core/shiki'
const theme =
editorThemeFromVscodeTheme ({
colors : { 'editor.background' :
'#18202b' , 'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme
} from
'@singapore-editor/core/shiki'
const theme =
editorThemeFromVscodeTheme ({
colors : { 'editor.background' :
'#18202b' , 'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from
'@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' ,
'editor.foreground' : '#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from
'@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' ,
'editor.foreground' : '#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from
'@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' , 'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from
'@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' , 'editor.foreground' :
'#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from '@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' , 'editor.foreground' : '#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from '@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' , 'editor.foreground' : '#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from '@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' , 'editor.foreground' : '#dce5ef' },
})
console . log ( theme )
import { editorThemeFromVscodeTheme } from '@singapore-editor/core/shiki'
const theme = editorThemeFromVscodeTheme ({
colors : { 'editor.background' : '#18202b' , 'editor.foreground' : '#dce5ef' },
})
console . log ( theme )
ts example Make live
3. Update a mounted editor
Call editor.setTheme(theme). React and Solid adapters accept theme options that update the live view. Plugin colour ids use the theme’s colors map. registerEditorColor in the rendering entry point declares a token and its defaults for a plugin.
Result
Editor background, foreground, selection and caret use the supplied colours. Add a syntax plugin for token colours. Syntax paint uses ::highlight(), which supports colour but cannot set font weight or font style.
If it doesn’t work
The gutter has a different background
Set gutter colour options. gutterLeadingInset controls the gutter’s leading space.
Syntax colours never change
Check that the syntax plugin has loaded its language and that your theme supplies syntax colours for the token categories it produces.
Continue with languages and tree-sitter and the generated rendering reference .