Skip to content

Commit a62d86b

Browse files
committed
add collapsible callouts to markdown builder
1 parent 680ab18 commit a62d86b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

jsEngine/api/markdown/AbstractMarkdownElementContainer.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ export abstract class AbstractMarkdownElementContainer extends AbstractMarkdownE
8686
}
8787

8888
createCallout(title: string, type: string, args: string = ''): CalloutElement {
89-
const element = new CalloutElement(title, type, args);
89+
const element = new CalloutElement(title, type, args, false, false);
90+
this.addElement(element);
91+
return element;
92+
}
93+
94+
createCollapsibleCallout(title: string, type: string, args: string = '', collapsed: boolean = false): CalloutElement {
95+
const element = new CalloutElement(title, type, args, true, collapsed);
9096
this.addElement(element);
9197
return element;
9298
}
@@ -338,21 +344,37 @@ export class CalloutElement extends AbstractMarkdownElementContainer {
338344
title: string;
339345
type: string;
340346
args: string;
347+
collapsible: boolean;
348+
collapsed: boolean;
341349

342-
constructor(title: string, type: string, args: string) {
350+
constructor(title: string, type: string, args: string, collapsible: boolean = false, collapsed: boolean = false) {
343351
super();
344352

345353
this.title = title;
346354
this.type = type;
347355
this.args = args;
356+
this.collapsible = collapsible;
357+
this.collapsed = collapsed;
348358
}
349359

350360
public allowElement(_: AbstractMarkdownElement): boolean {
351361
return true;
352362
}
353363

354364
public toString(): string {
355-
return `> [!${this.type}|${this.args}] ${this.title}` + `\n> ` + this.markdownElements.map(x => x.toString().replaceAll('\n', '\n> ')).join('\n> \n> ');
365+
return (
366+
`> [!${this.type}|${this.args}]${this.collapseChar()} ${this.title}` +
367+
`\n> ` +
368+
this.markdownElements.map(x => x.toString().replaceAll('\n', '\n> ')).join('\n> \n> ')
369+
);
370+
}
371+
372+
private collapseChar(): string {
373+
if (this.collapsible) {
374+
return this.collapsed ? '-' : '+';
375+
} else {
376+
return '';
377+
}
356378
}
357379
}
358380

0 commit comments

Comments
 (0)