瀏覽代碼

Merge pull request #17645 from ShirasawaSama/patch-28

feat: only retain one language supports for highlight.js to reduce bundle size (-1.58MB)
Tim Jaeryang Baek 2 周之前
父節點
當前提交
9710060c27
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      src/lib/components/common/RichTextInput.svelte

+ 7 - 2
src/lib/components/common/RichTextInput.svelte

@@ -139,7 +139,9 @@
 	import FormattingButtons from './RichTextInput/FormattingButtons.svelte';
 
 	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';
 
 	export let oncompositionstart = (e) => {};
@@ -147,7 +149,10 @@
 	export let onChange = (e) => {};
 
 	// 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;