mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 10:08:49 +01:00
Markdown document links should reveal cell in notebook (#153147)
Fixes #141024
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user