Markdown document links should reveal cell in notebook (#153147)

Fixes #141024
This commit is contained in:
Matt Bierner
2022-06-24 12:49:15 -07:00
committed by GitHub
parent 45427b2346
commit 00ad6bc3d4
2 changed files with 44 additions and 10 deletions

View File

@@ -77,21 +77,25 @@ export class TableOfContents {
.find(notebook => notebook.getCells().some(cell => cell.document === document));
if (notebook) {
const entries: TocEntry[] = [];
for (const cell of notebook.getCells()) {
if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) {
entries.push(...(await this.buildToc(parser, cell.document)));
}
}
return new TableOfContents(entries, parser.slugifier);
return TableOfContents.createForNotebook(parser, notebook);
}
}
return this.create(parser, document);
}
public static async createForNotebook(parser: IMdParser, notebook: vscode.NotebookDocument): Promise<TableOfContents> {
const entries: TocEntry[] = [];
for (const cell of notebook.getCells()) {
if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) {
entries.push(...(await this.buildToc(parser, cell.document)));
}
}
return new TableOfContents(entries, parser.slugifier);
}
private static async buildToc(parser: IMdParser, document: ITextDocument): Promise<TocEntry[]> {
const toc: TocEntry[] = [];
const tokens = await parser.tokenize(document);
@@ -184,7 +188,7 @@ export class MdTableOfContentsProvider extends Disposable {
private readonly _cache: MdDocumentInfoCache<TableOfContents>;
constructor(
parser: IMdParser,
private readonly parser: IMdParser,
workspace: IMdWorkspace,
private readonly logger: ILogger,
) {
@@ -202,4 +206,8 @@ export class MdTableOfContentsProvider extends Disposable {
public getForDocument(doc: ITextDocument): Promise<TableOfContents> {
return this._cache.getForDocument(doc);
}
public createForNotebook(notebook: vscode.NotebookDocument): Promise<TableOfContents> {
return TableOfContents.createForNotebook(this.parser, notebook);
}
}