@@ -12,6 +12,8 @@ import {
1212} from 'jsEngine/api/markdown/AbstractMarkdownElementContainer' ;
1313import { MarkdownBuilder } from 'jsEngine/api/markdown/MarkdownBuilder' ;
1414import { MarkdownString } from 'jsEngine/api/markdown/MarkdownString' ;
15+ import { validateAPIArgs } from 'jsEngine/utils/Validators' ;
16+ import { z } from 'zod' ;
1517
1618/**
1719 * The markdown API provides utilities for creating markdown using js.
@@ -27,7 +29,7 @@ export class MarkdownAPI {
2729 * Creates a markdown builder.
2830 */
2931 public createBuilder ( ) : MarkdownBuilder {
30- return new MarkdownBuilder ( ) ;
32+ return new MarkdownBuilder ( this . apiInstance ) ;
3133 }
3234
3335 /**
@@ -38,7 +40,9 @@ export class MarkdownAPI {
3840 * @param markdown the string to wrap
3941 */
4042 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 ) ;
4246 }
4347
4448 /**
@@ -47,7 +51,9 @@ export class MarkdownAPI {
4751 * @param text
4852 */
4953 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 ) ;
5157 }
5258
5359 /**
@@ -56,7 +62,9 @@ export class MarkdownAPI {
5662 * @param text
5763 */
5864 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 ) ;
6068 }
6169
6270 /**
@@ -65,7 +73,9 @@ export class MarkdownAPI {
6573 * @param text
6674 */
6775 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 ) ;
6979 }
7080
7181 /**
@@ -74,7 +84,9 @@ export class MarkdownAPI {
7484 * @param text
7585 */
7686 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 ) ;
7890 }
7991
8092 /**
@@ -83,7 +95,9 @@ export class MarkdownAPI {
8395 * @param text
8496 */
8597 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 ) ;
87101 }
88102
89103 /**
@@ -92,7 +106,9 @@ export class MarkdownAPI {
92106 * @param content
93107 */
94108 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 ) ;
96112 }
97113
98114 /**
@@ -102,14 +118,16 @@ export class MarkdownAPI {
102118 * @param content the text of the heading
103119 */
104120 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 ) ;
106124 }
107125
108126 /**
109127 * Creates a new markdown block quote element.
110128 */
111129 public createBlockQuote ( ) : BlockQuoteElement {
112- return new BlockQuoteElement ( ) ;
130+ return new BlockQuoteElement ( this . apiInstance ) ;
113131 }
114132
115133 /**
@@ -120,7 +138,23 @@ export class MarkdownAPI {
120138 * @param args the callout args, optional
121139 */
122140 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 ) ;
124158 }
125159
126160 /**
@@ -130,7 +164,9 @@ export class MarkdownAPI {
130164 * @param content the content of the code block
131165 */
132166 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 ) ;
134170 }
135171
136172 /**
@@ -140,7 +176,9 @@ export class MarkdownAPI {
140176 * @param body the table body
141177 */
142178 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 ) ;
144182 }
145183
146184 /**
@@ -149,6 +187,8 @@ export class MarkdownAPI {
149187 * @param ordered whether the list should be ordered or not (use 1. or -)
150188 */
151189 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 ) ;
153193 }
154194}
0 commit comments