From 78597fd0264dd87549666bac8ded0dbcf8e2aa42 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 17 Jun 2022 14:25:54 -0700 Subject: [PATCH] Don't hardcode use of github slugifier (#152507) Use `engine.slugifier` for this instead --- .../src/tableOfContents.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/extensions/markdown-language-features/src/tableOfContents.ts b/extensions/markdown-language-features/src/tableOfContents.ts index 6935763b3ec..0f28f9fa635 100644 --- a/extensions/markdown-language-features/src/tableOfContents.ts +++ b/extensions/markdown-language-features/src/tableOfContents.ts @@ -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 { 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 { @@ -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)); } }