c063 1.4.7 → 1.4.8
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.
- package/dist/components/CodeBlock.d.ts +1 -0
- package/dist/components/CodeBlock.js +1 -0
- package/dist/components/CodeLine.d.ts +1 -0
- package/dist/components/CodeLine.js +2 -1
- package/dist/components/CodeToken.d.ts +1 -0
- package/dist/components/CodeToken.js +1 -0
- package/dist/libs/index.d.ts +1 -0
- package/dist/libs/index.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/index.js +11 -0
- package/package.json +1 -1
- package/src/components/CodeBlock.tsx +1 -0
- package/src/components/CodeLine.tsx +2 -1
- package/src/components/CodeToken.tsx +1 -0
- package/src/libs/index.tsx +2 -0
- package/src/types/index.ts +3 -2
- package/src/utils/index.tsx +23 -3
|
@@ -6,6 +6,7 @@ import { CodeBlockProps } from "../types/index";
|
|
|
6
6
|
* @param props.tokenLines 所有程式碼行的 token 陣列
|
|
7
7
|
* @param props.showLineNumbers 是否顯示行號,預設為 true
|
|
8
8
|
* @param props.lineNumberStyle 行號的自訂樣式
|
|
9
|
+
* @param props.theme 主題
|
|
9
10
|
* @param rest 其他傳遞給 <pre> 的屬性
|
|
10
11
|
* @returns JSX 元素,呈現語法高亮的程式碼區塊
|
|
11
12
|
*/
|
|
@@ -7,6 +7,7 @@ import { CodeLine } from "./CodeLine";
|
|
|
7
7
|
* @param props.tokenLines 所有程式碼行的 token 陣列
|
|
8
8
|
* @param props.showLineNumbers 是否顯示行號,預設為 true
|
|
9
9
|
* @param props.lineNumberStyle 行號的自訂樣式
|
|
10
|
+
* @param props.theme 主題
|
|
10
11
|
* @param rest 其他傳遞給 <pre> 的屬性
|
|
11
12
|
* @returns JSX 元素,呈現語法高亮的程式碼區塊
|
|
12
13
|
*/
|
|
@@ -5,6 +5,7 @@ import { CodeLineProps } from "../types/index";
|
|
|
5
5
|
* @template T 元件渲染類型,例如 <code>、<span> 等
|
|
6
6
|
* @param props.tokens 該行所包含的語法 token 陣列
|
|
7
7
|
* @param props.style 自訂樣式,會與 whiteSpace: pre-wrap 合併
|
|
8
|
+
* @param props.theme 主題
|
|
8
9
|
* @param rest 其他 HTMLAttributes
|
|
9
10
|
* @returns JSX 元素,呈現語法 token 的單行程式碼
|
|
10
11
|
*/
|
|
@@ -6,6 +6,7 @@ import { CodeToken } from "./CodeToken";
|
|
|
6
6
|
* @template T 元件渲染類型,例如 <code>、<span> 等
|
|
7
7
|
* @param props.tokens 該行所包含的語法 token 陣列
|
|
8
8
|
* @param props.style 自訂樣式,會與 whiteSpace: pre-wrap 合併
|
|
9
|
+
* @param props.theme 主題
|
|
9
10
|
* @param rest 其他 HTMLAttributes
|
|
10
11
|
* @returns JSX 元素,呈現語法 token 的單行程式碼
|
|
11
12
|
*/
|
|
@@ -13,6 +14,6 @@ export const CodeLine = ({ style, tokens, theme, ...rest }) => {
|
|
|
13
14
|
return (_jsx("code", { ...rest, style: {
|
|
14
15
|
whiteSpace: "pre-wrap",
|
|
15
16
|
...style,
|
|
16
|
-
}, children: tokens.map((token, index) => (_jsx(CodeToken, { theme: theme, ...token },
|
|
17
|
+
}, children: tokens.map((token, index) => (_jsx(CodeToken, { theme: theme, ...token }, index))) }));
|
|
17
18
|
};
|
|
18
19
|
CodeLine.displayName = "CodeLine";
|
package/dist/libs/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ declare const _themeRegistry: {
|
|
|
15
15
|
};
|
|
16
16
|
export declare const themes: (keyof typeof _themeRegistry)[];
|
|
17
17
|
export declare const themeMap: Record<CodeTheme, Record<CodeTokenType, React.CSSProperties["color"]>>;
|
|
18
|
+
export declare const parsableLanguages: readonly ["javascript"];
|
|
18
19
|
export {};
|
package/dist/libs/index.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { themes } from "../libs";
|
|
1
|
+
import { parsableLanguages, themes } from "../libs";
|
|
2
2
|
import { AsComponentProps, OverrideProps } from "./common";
|
|
3
3
|
/**
|
|
4
4
|
* 用於表示語法高亮中每個 token 的語意分類,對應於 `<CodeToken />` 中的 `type`。
|
|
5
5
|
*
|
|
6
6
|
* 每個類型會對應特定的顏色與用途,例如關鍵字、數字、字串、註解等,
|
|
7
|
-
* 可配合 `codeColoreMap` 指定顯示樣式。s
|
|
8
7
|
*
|
|
9
8
|
* 類型分為以下幾大類:
|
|
10
9
|
*
|
|
@@ -114,3 +113,4 @@ export type CodeBlockProps<T extends React.ElementType> = OverrideProps<React.HT
|
|
|
114
113
|
*/
|
|
115
114
|
theme?: CodeTheme;
|
|
116
115
|
}>;
|
|
116
|
+
export type ParsableLanguage = (typeof parsableLanguages)[number];
|
package/dist/utils/index.js
CHANGED
|
@@ -53,3 +53,14 @@ export const extractTokenContent = (token) => {
|
|
|
53
53
|
return _extract(token.children);
|
|
54
54
|
};
|
|
55
55
|
export default c063;
|
|
56
|
+
/**
|
|
57
|
+
* 待實現
|
|
58
|
+
*/
|
|
59
|
+
const _parseTokens = new Proxy({}, {
|
|
60
|
+
get: (_, prop) => {
|
|
61
|
+
const parser = (content) => {
|
|
62
|
+
return [];
|
|
63
|
+
};
|
|
64
|
+
return parser;
|
|
65
|
+
},
|
|
66
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "c063",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.8",
|
|
5
5
|
"description": "A React component for displaying code snippets with syntax highlighting.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -7,6 +7,7 @@ import { CodeLine } from "./CodeLine";
|
|
|
7
7
|
* @param props.tokenLines 所有程式碼行的 token 陣列
|
|
8
8
|
* @param props.showLineNumbers 是否顯示行號,預設為 true
|
|
9
9
|
* @param props.lineNumberStyle 行號的自訂樣式
|
|
10
|
+
* @param props.theme 主題
|
|
10
11
|
* @param rest 其他傳遞給 <pre> 的屬性
|
|
11
12
|
* @returns JSX 元素,呈現語法高亮的程式碼區塊
|
|
12
13
|
*/
|
|
@@ -6,6 +6,7 @@ import { CodeToken } from "./CodeToken";
|
|
|
6
6
|
* @template T 元件渲染類型,例如 <code>、<span> 等
|
|
7
7
|
* @param props.tokens 該行所包含的語法 token 陣列
|
|
8
8
|
* @param props.style 自訂樣式,會與 whiteSpace: pre-wrap 合併
|
|
9
|
+
* @param props.theme 主題
|
|
9
10
|
* @param rest 其他 HTMLAttributes
|
|
10
11
|
* @returns JSX 元素,呈現語法 token 的單行程式碼
|
|
11
12
|
*/
|
|
@@ -24,7 +25,7 @@ export const CodeLine = <T extends React.ElementType = "span">({
|
|
|
24
25
|
}}
|
|
25
26
|
>
|
|
26
27
|
{tokens.map((token, index) => (
|
|
27
|
-
<CodeToken key={
|
|
28
|
+
<CodeToken key={index} theme={theme} {...token} />
|
|
28
29
|
))}
|
|
29
30
|
</code>
|
|
30
31
|
);
|
package/src/libs/index.tsx
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { themes } from "../libs";
|
|
1
|
+
import { parsableLanguages, themes } from "../libs";
|
|
2
2
|
import { AsComponentProps, OverrideProps } from "./common";
|
|
3
3
|
/**
|
|
4
4
|
* 用於表示語法高亮中每個 token 的語意分類,對應於 `<CodeToken />` 中的 `type`。
|
|
5
5
|
*
|
|
6
6
|
* 每個類型會對應特定的顏色與用途,例如關鍵字、數字、字串、註解等,
|
|
7
|
-
* 可配合 `codeColoreMap` 指定顯示樣式。s
|
|
8
7
|
*
|
|
9
8
|
* 類型分為以下幾大類:
|
|
10
9
|
*
|
|
@@ -143,3 +142,5 @@ export type CodeBlockProps<T extends React.ElementType> = OverrideProps<
|
|
|
143
142
|
theme?: CodeTheme;
|
|
144
143
|
}
|
|
145
144
|
>;
|
|
145
|
+
|
|
146
|
+
export type ParsableLanguage = (typeof parsableLanguages)[number];
|
package/src/utils/index.tsx
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
CodeTokenBuilder,
|
|
4
|
+
CodeTokenProps,
|
|
5
|
+
CodeTokenType,
|
|
6
|
+
ParsableLanguage,
|
|
7
|
+
} from "../types";
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* 語法 token 的建構器集合,每個 key 對應一種語法類型(如 `keyword-blue`, `string`, `comment` 等),
|
|
@@ -64,4 +68,20 @@ export const extractTokenContent = <T extends React.ElementType>(
|
|
|
64
68
|
return _extract(token.children);
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
export default c063;
|
|
71
|
+
export default c063;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 待實現
|
|
76
|
+
*/
|
|
77
|
+
const _parseTokens = new Proxy(
|
|
78
|
+
{},
|
|
79
|
+
{
|
|
80
|
+
get: (_, prop: ParsableLanguage) => {
|
|
81
|
+
const parser = (content: string): CodeTokenProps<"span">[][] => {
|
|
82
|
+
return [];
|
|
83
|
+
};
|
|
84
|
+
return parser;
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
) as Record<ParsableLanguage, (content: string) => CodeTokenProps<"span">[][]>;
|