Code languages

A code block's language is free text by default. When the host knows which languages its site can highlight, it gives the list with provideCodeLanguages, and the field becomes a dropdown of them, with None first. Nested editors inherit the list. A stored language that is missing from the list stays an option, so an older document loses nothing.

code.ts
interface CodeLanguage {
	value: string;  // stored in the block: props.lang
	label?: string; // shown in the dropdown (default: the value)
}
function provideCodeLanguages(own: () => (string | CodeLanguage)[] | undefined): void;
function useCodeLanguages(): () => CodeLanguage[]; // empty: free text

A dropdown of four languages

Open the code block’s fields bar and pick a language.

const answer: number = 42;