Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extensions/langs/gen-langs-map.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ const sorted = Array.from(mapObj.entries()).sort((a, b) => a[0].localeCompare(b[
let out = '';
out += `// auto-generated by gen-langs-map.cjs – DO NOT EDIT\n`;
out += importLines.join('\n') + (importLines.length ? '\n\n' : '');
out += `export const langs: Record<string, () => LanguageSupport | StreamLanguage<unknown>> = {\n`;
out += `export const langs = {\n`;
for (const [k, v] of sorted) {
const key = /^[a-z0-9_+-]+$/i.test(k) ? k : JSON.stringify(k);
out += ` ${JSON.stringify(k)}: ${v},\n`;
}
out += `};\n\n`;
out += `} satisfies Record<string, () => LanguageSupport | StreamLanguage<unknown>>;\n\n`;

out += `export const langNames = Object.keys(langs) as LanguageName[];\n\n`;
out += `export type LanguageName = keyof typeof langs;\n`;
Expand Down
6 changes: 3 additions & 3 deletions www/src/pages/home/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type Extension } from '@codemirror/state';
import CodeMirror, { ReactCodeMirrorProps, BasicSetupOptions } from '@uiw/react-codemirror';
import styled from 'styled-components';
import * as alls from '@uiw/codemirror-themes-all';
import { langs } from '@uiw/codemirror-extensions-langs';
import { langs, LanguageName } from '@uiw/codemirror-extensions-langs';
import { Select } from './Select';
import { Options } from '../extensions/basic-setup/example';
import { useTheme } from '../../utils/useTheme';
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function Example() {
crosshairCursor: false,
});

function handleLangChange(lang: string) {
function handleLangChange(lang: LanguageName) {
try {
import(`code-example/txt/sample.${lang.toLocaleLowerCase()}.txt`)
.then((data) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ export default function Example() {
label="Lang"
options={Object.keys(langs).sort()}
value={mode}
onChange={(evn) => handleLangChange(evn.target.value)}
onChange={(evn) => handleLangChange(evn.target.value as LanguageName)}
/>
<Select
label="Website Theme"
Expand Down