mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Don't hardcode use of github slugifier (#152507)
Use `engine.slugifier` for this instead
This commit is contained in:
parent
993da80fa2
commit
78597fd026
|
@ -6,7 +6,7 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { MdDocumentInfoCache } from './languageFeatures/workspaceCache';
|
||||
import { MarkdownEngine } from './markdownEngine';
|
||||
import { githubSlugifier, Slug } from './slugify';
|
||||
import { githubSlugifier, Slug, Slugifier } from './slugify';
|
||||
import { Disposable } from './util/dispose';
|
||||
import { isMarkdownFile } from './util/file';
|
||||
import { MdWorkspaceContents, SkinnyTextDocument } from './workspaceContents';
|
||||
|
@ -65,7 +65,7 @@ export class TableOfContents {
|
|||
|
||||
public static async create(engine: MarkdownEngine, document: SkinnyTextDocument,): Promise<TableOfContents> {
|
||||
const entries = await this.buildToc(engine, document);
|
||||
return new TableOfContents(entries);
|
||||
return new TableOfContents(entries, engine.slugifier);
|
||||
}
|
||||
|
||||
public static async createForDocumentOrNotebook(engine: MarkdownEngine, document: SkinnyTextDocument): Promise<TableOfContents> {
|
||||
|
@ -82,7 +82,7 @@ export class TableOfContents {
|
|||
}
|
||||
}
|
||||
|
||||
return new TableOfContents(entries);
|
||||
return new TableOfContents(entries, engine.slugifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,11 +103,11 @@ export class TableOfContents {
|
|||
const lineNumber = heading.map[0];
|
||||
const line = document.lineAt(lineNumber);
|
||||
|
||||
let slug = githubSlugifier.fromHeading(line.text);
|
||||
let slug = engine.slugifier.fromHeading(line.text);
|
||||
const existingSlugEntry = existingSlugEntries.get(slug.value);
|
||||
if (existingSlugEntry) {
|
||||
++existingSlugEntry.count;
|
||||
slug = githubSlugifier.fromHeading(slug.value + '-' + existingSlugEntry.count);
|
||||
slug = engine.slugifier.fromHeading(slug.value + '-' + existingSlugEntry.count);
|
||||
} else {
|
||||
existingSlugEntries.set(slug.value, { count: 0 });
|
||||
}
|
||||
|
@ -163,14 +163,15 @@ export class TableOfContents {
|
|||
return header.replace(/^\s*#+\s*(.*?)(\s+#+)?$/, (_, word) => word.trim());
|
||||
}
|
||||
|
||||
public static readonly empty = new TableOfContents([]);
|
||||
public static readonly empty = new TableOfContents([], githubSlugifier);
|
||||
|
||||
private constructor(
|
||||
public readonly entries: readonly TocEntry[],
|
||||
private readonly slugifier: Slugifier,
|
||||
) { }
|
||||
|
||||
public lookup(fragment: string): TocEntry | undefined {
|
||||
const slug = githubSlugifier.fromHeading(fragment);
|
||||
const slug = this.slugifier.fromHeading(fragment);
|
||||
return this.entries.find(entry => entry.slug.equals(slug));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue