Book Editing: Support adding new sections to a book (#17074)

* add a new section command
This commit is contained in:
Barbara Valdez
2021-09-14 11:31:43 -07:00
committed by GitHub
parent f92e6d24d4
commit ce13d01efb
10 changed files with 65 additions and 19 deletions

View File

@@ -18,7 +18,7 @@ export interface IBookTocManager {
updateBook(sources: BookTreeItem[], target: BookTreeItem, targetSection?: JupyterBookSection): Promise<void>;
removeNotebook(element: BookTreeItem): Promise<void>;
createBook(bookContentPath: string, contentFolder: string): Promise<void>;
addNewFile(pathDetails: TocEntryPathHandler, bookItem: BookTreeItem): Promise<void>;
addNewTocEntry(pathDetails: TocEntryPathHandler, bookItem: BookTreeItem, isSection?: boolean): Promise<void>;
recovery(): Promise<void>;
}
@@ -443,7 +443,7 @@ export class BookTocManager implements IBookTocManager {
}
}
public async addNewFile(pathDetails: TocEntryPathHandler, bookItem: BookTreeItem): Promise<void> {
public async addNewTocEntry(pathDetails: TocEntryPathHandler, bookItem: BookTreeItem, isSection?: boolean): Promise<void> {
let findSection: JupyterBookSection | undefined = undefined;
await fs.writeFile(pathDetails.filePath, '');
if (bookItem.contextValue === 'section') {
@@ -453,6 +453,11 @@ export class BookTocManager implements IBookTocManager {
title: pathDetails.titleInTocEntry,
file: pathDetails.fileInTocEntry
};
if (isSection) {
fileEntryInToc.sections = [];
}
if (bookItem.book.version === BookVersion.v1) {
fileEntryInToc = convertTo(BookVersion.v1, fileEntryInToc);
}