Files
azuredatastudio/extensions/notebook/src/book/tocEntryPathHandler.ts
Barbara Valdez fde5caa9a4 Add documentation and fix paths (#14948)
* use posix relative path

* add doc link in dialog

* rename book to Jupyter book
2021-04-02 15:44:25 -07:00

27 lines
1.3 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import { FileExtension } from '../common/utils';
export class TocEntryPathHandler {
public readonly fileInTocEntry: string;
public readonly titleInTocEntry: string;
public readonly fileExtension: FileExtension;
/**
* Creates an object that contains the specific format for title and file entries in a Jupyter Book table of contents
* that is compatible on Windows and Mac.
*/
constructor(public readonly filePath: string, public readonly bookRoot: string, title?: string) {
//To keep consistency how the file entries are in Jupyter Book toc on Windows and Mac.
const tocRelativePath = path.posix.join(path.posix.sep, path.posix.relative(bookRoot, filePath));
const pathDetails = path.parse(tocRelativePath);
this.fileInTocEntry = tocRelativePath.replace(pathDetails.ext, '');
this.titleInTocEntry = title ?? pathDetails.name;
this.fileExtension = pathDetails.ext === FileExtension.Notebook ? FileExtension.Notebook : FileExtension.Markdown;
}
}