Create `Heading.toMarkdown` method
This commit is contained in:
parent
60b8f7e5a9
commit
4a9457efd7
|
@ -10,10 +10,14 @@ export class Heading {
|
||||||
treeLevel: number,
|
treeLevel: number,
|
||||||
parent: Heading | null,
|
parent: Heading | null,
|
||||||
) {
|
) {
|
||||||
Object.assign(this, {title, hLevel, treeLevel, parent})
|
Object.assign(this, { title, hLevel, treeLevel, parent });
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent(hLevel: number): Heading | undefined {
|
getParent(hLevel: number): Heading | undefined {
|
||||||
return this.hLevel < hLevel ? this : this.parent?.getParent(hLevel);
|
return this.hLevel < hLevel ? this : this.parent?.getParent(hLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toMarkdown(): string {
|
||||||
|
return `${"\t".repeat(this.treeLevel)}- [ ] ${this.title}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,11 +75,7 @@ export default class OutlineTaskListPlugin extends Plugin {
|
||||||
* Build the task list from the specified outline.
|
* Build the task list from the specified outline.
|
||||||
*/
|
*/
|
||||||
static buildTasklist(outline: Outline): string {
|
static buildTasklist(outline: Outline): string {
|
||||||
return outline
|
return outline.map((heading) => heading.toMarkdown()).join("\r\n");
|
||||||
.map(
|
|
||||||
(heading) => `${"\t".repeat(heading.treeLevel)}- [ ] ${heading.title}`,
|
|
||||||
)
|
|
||||||
.join("\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue