@@ -12,6 +12,8 @@ import {
12
12
} from 'jsEngine/api/markdown/AbstractMarkdownElementContainer' ;
13
13
import { MarkdownBuilder } from 'jsEngine/api/markdown/MarkdownBuilder' ;
14
14
import { MarkdownString } from 'jsEngine/api/markdown/MarkdownString' ;
15
+ import { validateAPIArgs } from 'jsEngine/utils/Validators' ;
16
+ import { z } from 'zod' ;
15
17
16
18
/**
17
19
* The markdown API provides utilities for creating markdown using js.
@@ -27,7 +29,7 @@ export class MarkdownAPI {
27
29
* Creates a markdown builder.
28
30
*/
29
31
public createBuilder ( ) : MarkdownBuilder {
30
- return new MarkdownBuilder ( ) ;
32
+ return new MarkdownBuilder ( this . apiInstance ) ;
31
33
}
32
34
33
35
/**
@@ -38,7 +40,9 @@ export class MarkdownAPI {
38
40
* @param markdown the string to wrap
39
41
*/
40
42
public create ( markdown : string ) : MarkdownString {
41
- return new MarkdownString ( markdown ) ;
43
+ validateAPIArgs ( z . object ( { markdown : z . string ( ) } ) , { markdown } ) ;
44
+
45
+ return new MarkdownString ( this . apiInstance , markdown ) ;
42
46
}
43
47
44
48
/**
@@ -47,7 +51,9 @@ export class MarkdownAPI {
47
51
* @param text
48
52
*/
49
53
public createText ( text : string ) : TextElement {
50
- return new TextElement ( text , false , false , false ) ;
54
+ validateAPIArgs ( z . object ( { text : z . string ( ) } ) , { text } ) ;
55
+
56
+ return new TextElement ( this . apiInstance , text , false , false , false ) ;
51
57
}
52
58
53
59
/**
@@ -56,7 +62,9 @@ export class MarkdownAPI {
56
62
* @param text
57
63
*/
58
64
public createBoldText ( text : string ) : TextElement {
59
- return new TextElement ( text , true , false , false ) ;
65
+ validateAPIArgs ( z . object ( { text : z . string ( ) } ) , { text } ) ;
66
+
67
+ return new TextElement ( this . apiInstance , text , true , false , false ) ;
60
68
}
61
69
62
70
/**
@@ -65,7 +73,9 @@ export class MarkdownAPI {
65
73
* @param text
66
74
*/
67
75
public createCursiveText ( text : string ) : TextElement {
68
- return new TextElement ( text , false , true , false ) ;
76
+ validateAPIArgs ( z . object ( { text : z . string ( ) } ) , { text } ) ;
77
+
78
+ return new TextElement ( this . apiInstance , text , false , true , false ) ;
69
79
}
70
80
71
81
/**
@@ -74,7 +84,9 @@ export class MarkdownAPI {
74
84
* @param text
75
85
*/
76
86
public createUnderlinedText ( text : string ) : TextElement {
77
- return new TextElement ( text , false , false , true ) ;
87
+ validateAPIArgs ( z . object ( { text : z . string ( ) } ) , { text } ) ;
88
+
89
+ return new TextElement ( this . apiInstance , text , false , false , true ) ;
78
90
}
79
91
80
92
/**
@@ -83,7 +95,9 @@ export class MarkdownAPI {
83
95
* @param text
84
96
*/
85
97
public createCode ( text : string ) : CodeElement {
86
- return new CodeElement ( text ) ;
98
+ validateAPIArgs ( z . object ( { text : z . string ( ) } ) , { text } ) ;
99
+
100
+ return new CodeElement ( this . apiInstance , text ) ;
87
101
}
88
102
89
103
/**
@@ -92,7 +106,9 @@ export class MarkdownAPI {
92
106
* @param content
93
107
*/
94
108
public createParagraph ( content : string ) : ParagraphElement {
95
- return new ParagraphElement ( content ) ;
109
+ validateAPIArgs ( z . object ( { content : z . string ( ) } ) , { content } ) ;
110
+
111
+ return new ParagraphElement ( this . apiInstance , content ) ;
96
112
}
97
113
98
114
/**
@@ -102,14 +118,16 @@ export class MarkdownAPI {
102
118
* @param content the text of the heading
103
119
*/
104
120
public createHeading ( level : number , content : string ) : HeadingElement {
105
- return new HeadingElement ( level , content ) ;
121
+ validateAPIArgs ( z . object ( { level : z . number ( ) , content : z . string ( ) } ) , { level, content } ) ;
122
+
123
+ return new HeadingElement ( this . apiInstance , level , content ) ;
106
124
}
107
125
108
126
/**
109
127
* Creates a new markdown block quote element.
110
128
*/
111
129
public createBlockQuote ( ) : BlockQuoteElement {
112
- return new BlockQuoteElement ( ) ;
130
+ return new BlockQuoteElement ( this . apiInstance ) ;
113
131
}
114
132
115
133
/**
@@ -120,7 +138,23 @@ export class MarkdownAPI {
120
138
* @param args the callout args, optional
121
139
*/
122
140
public createCallout ( title : string , type : string , args : string = '' ) : CalloutElement {
123
- return new CalloutElement ( title , type , args ) ;
141
+ validateAPIArgs ( z . object ( { title : z . string ( ) , type : z . string ( ) , args : z . string ( ) } ) , { title, type, args } ) ;
142
+
143
+ return new CalloutElement ( this . apiInstance , title , type , args ) ;
144
+ }
145
+
146
+ /**
147
+ * Creates a new markdown collapsible callout element.
148
+ *
149
+ * @param title the title of the callout
150
+ * @param type the type of the callout
151
+ * @param args the callout args, optional
152
+ * @param collapsed whether the callout should be collapsed by default, optional
153
+ */
154
+ createCollapsibleCallout ( title : string , type : string , args : string = '' , collapsed : boolean = false ) : CalloutElement {
155
+ validateAPIArgs ( z . object ( { title : z . string ( ) , type : z . string ( ) , args : z . string ( ) , collapsed : z . boolean ( ) } ) , { title, type, args, collapsed } ) ;
156
+
157
+ return new CalloutElement ( this . apiInstance , title , type , args , true , collapsed ) ;
124
158
}
125
159
126
160
/**
@@ -130,7 +164,9 @@ export class MarkdownAPI {
130
164
* @param content the content of the code block
131
165
*/
132
166
public createCodeBlock ( language : string , content : string ) : CodeBlockElement {
133
- return new CodeBlockElement ( language , content ) ;
167
+ validateAPIArgs ( z . object ( { language : z . string ( ) , content : z . string ( ) } ) , { language, content } ) ;
168
+
169
+ return new CodeBlockElement ( this . apiInstance , language , content ) ;
134
170
}
135
171
136
172
/**
@@ -140,7 +176,9 @@ export class MarkdownAPI {
140
176
* @param body the table body
141
177
*/
142
178
public createTable ( header : string [ ] , body : string [ ] [ ] ) : TableElement {
143
- return new TableElement ( header , body ) ;
179
+ validateAPIArgs ( z . object ( { header : z . array ( z . string ( ) ) , body : z . array ( z . array ( z . string ( ) ) ) } ) , { header, body } ) ;
180
+
181
+ return new TableElement ( this . apiInstance , header , body ) ;
144
182
}
145
183
146
184
/**
@@ -149,6 +187,8 @@ export class MarkdownAPI {
149
187
* @param ordered whether the list should be ordered or not (use 1. or -)
150
188
*/
151
189
createList ( ordered : boolean ) : ListElement {
152
- return new ListElement ( ordered ) ;
190
+ validateAPIArgs ( z . object ( { ordered : z . boolean ( ) } ) , { ordered } ) ;
191
+
192
+ return new ListElement ( this . apiInstance , ordered ) ;
153
193
}
154
194
}
0 commit comments