feat: only retain one language supports for highlight.js to reduce bundle size

This commit is contained in:
Shirasawa 2025-09-22 16:00:46 +08:00 committed by GitHub
parent fb3b736a35
commit 2edfde1990
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -139,7 +139,9 @@
import FormattingButtons from './RichTextInput/FormattingButtons.svelte'; import FormattingButtons from './RichTextInput/FormattingButtons.svelte';
import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants'; import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
import { all, createLowlight } from 'lowlight'; import { createLowlight } from 'lowlight';
import hljs from 'highlight.js';
import type { SocketIOCollaborationProvider } from './RichTextInput/Collaboration'; import type { SocketIOCollaborationProvider } from './RichTextInput/Collaboration';
export let oncompositionstart = (e) => {}; export let oncompositionstart = (e) => {};
@ -147,7 +149,10 @@
export let onChange = (e) => {}; export let onChange = (e) => {};
// create a lowlight instance with all languages loaded // create a lowlight instance with all languages loaded
const lowlight = createLowlight(all); const lowlight = createLowlight(hljs.listLanguages().reduce((obj, lang) => {
obj[lang] = () => hljs.getLanguage(lang);
return obj;
}, {} as Record<string, any>));
export let editor: Editor | null = null; export let editor: Editor | null = null;