@wallarm-org/design-system 0.16.1 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,16 +28,19 @@ const CodeSnippetRoot = ({ code, language = 'text', size = 'sm', lines = {}, sta
|
|
|
28
28
|
const [tokens, setTokens] = useState(null);
|
|
29
29
|
const [isLoading, setIsLoading] = useState(false);
|
|
30
30
|
const adapter = adapterContext?.adapter ?? plainAdapter;
|
|
31
|
+
const normalizedCode = useMemo(()=>code.replace(/\r\n?/g, '\n'), [
|
|
32
|
+
code
|
|
33
|
+
]);
|
|
31
34
|
useEffect(()=>{
|
|
32
35
|
let cancelled = false;
|
|
33
36
|
const highlight = async ()=>{
|
|
34
37
|
setIsLoading(true);
|
|
35
38
|
try {
|
|
36
|
-
const result = await adapter.highlight(
|
|
39
|
+
const result = await adapter.highlight(normalizedCode, language);
|
|
37
40
|
if (!cancelled) setTokens(result.tokens);
|
|
38
41
|
} catch {
|
|
39
42
|
if (!cancelled) {
|
|
40
|
-
const plainTokens =
|
|
43
|
+
const plainTokens = normalizedCode.split('\n').map((line)=>[
|
|
41
44
|
{
|
|
42
45
|
content: line,
|
|
43
46
|
type: 'plain'
|
|
@@ -54,7 +57,7 @@ const CodeSnippetRoot = ({ code, language = 'text', size = 'sm', lines = {}, sta
|
|
|
54
57
|
cancelled = true;
|
|
55
58
|
};
|
|
56
59
|
}, [
|
|
57
|
-
|
|
60
|
+
normalizedCode,
|
|
58
61
|
language,
|
|
59
62
|
adapter
|
|
60
63
|
]);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Prism } from "prism-react-renderer";
|
|
2
2
|
("u" > typeof globalThis ? globalThis : window).Prism = Prism;
|
|
3
|
-
let
|
|
3
|
+
let languagesPromise = null;
|
|
4
4
|
async function loadAdditionalLanguages() {
|
|
5
|
-
if (
|
|
6
|
-
languagesLoaded = true;
|
|
7
|
-
await Promise.all([
|
|
5
|
+
if (!languagesPromise) languagesPromise = Promise.all([
|
|
8
6
|
import("prismjs/components/prism-bash"),
|
|
9
7
|
import("prismjs/components/prism-http")
|
|
10
8
|
]);
|
|
9
|
+
return languagesPromise;
|
|
11
10
|
}
|
|
12
11
|
const SUPPORTED_LANGUAGES = [
|
|
13
12
|
"javascript",
|