-
Notifications
You must be signed in to change notification settings - Fork 3
/
codecake.d.ts
96 lines (83 loc) · 2.59 KB
/
codecake.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
interface CodeCakeOptions {
/**
* The language of the code. This value will be also passed as the second argument
* of the function provided in {@link CodeCakeOptions.highlight}
* @default ""
*/
language: string;
/**
* If set to true, the editor will be in read-only mode
* @default false
*/
readOnly: boolean;
/**
* If set to true, the editor displays line numbers
* @default false
*/
lineNumbers: boolean;
/**
* If set to true, the editor will use the tab character "\t" for indentation instead of spaces
* @default false
*/
indentWithTabs: boolean;
/**
* The number of spaces for a tab
* @default 4
*/
tabSize: number;
/**
* Automatically close brackets, braces, parentheses, and quotes.
* @default true
*/
addClosing: boolean;
/**
* Allows the text to wrap to the next line when it reaches the end of the editor width
* @default false
*/
lineWrap: boolean;
/**
* The function to use to highlight the code. Note that this does not support other
* syntax highlighters due to the lineWrap feature of CodeCake.
* @param code The code the be highlighted
* @param language The language to highlight the code in
* @returns An HTML string representing the highlighted code
* @default CodeCake.highlight
*/
highlight: (code: string, language: string) => string;
/**
* A custom classname to customize the editing area
* @default ""
*/
className: "codecake-light" | "codecake-dark" | string;
}
interface CodeCakeEditor {
/**
* @returns The code in the editor
*/
getCode(): string;
/**
* Sets the code in the editor
* @param code The code to set
*/
setCode(code: string): void;
/**
* Triggers a callback whenever the code changes
* @param callback The function to call when the code changes
*/
onChange(callback: (code: string) => void): void;
}
declare module 'codecake' {
/**
* Creates a new CodeCake editor
* @param parent The parent div to append the editor to
* @param options The options to use for the editor
*/
export function create(parent: HTMLDivElement, options?: Partial<CodeCakeOptions>): CodeCakeEditor
/**
* Highlights code using the specified language
* @param code The code to highlight
* @param language The language to highlight the code in
* @returns An HTML string representing the highlighted code
*/
export function highlight(code: string, language: string): string
}