Skip to content

Commit 831a412

Browse files
committed
x
1 parent 51f1231 commit 831a412

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

package-lock.json

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/suite/integration/toc.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Selection } from "vscode";
22
import { resetConfiguration, updateConfiguration } from "../util/configuration";
3-
import { testCommand, Test_Md_File_Path } from "../util/generic";
3+
import { testCommand, Test_Md_File_Path, Test_Md_File_Regex_Path } from "../util/generic";
44

55
suite("TOC.", () => {
66
suiteSetup(async () => {
@@ -437,10 +437,16 @@ suite("TOC.", () => {
437437
await resetConfiguration();
438438
});
439439

440-
test("Exclude omitted headings (`toc.omittedFromToc`)", async () => {
440+
test("Exclude omitted headings with regex filename (`toc.omittedFromToc`)", async () => {
441441
await updateConfiguration({
442442
config: [["markdown.extension.toc.omittedFromToc", {
443-
'*.md': ['# Head 1'],
443+
[Test_Md_File_Regex_Path.fsPath]: [
444+
// With more than one space between sharps and text.
445+
'# Introduction',
446+
// With spaces before sharps ans special chars.
447+
' ## Ignored - with "special" ~ chars',
448+
'## Underlined heading'
449+
],
444450
'not-ignored.md': ['# Head 1']
445451
}]]
446452
});

src/test/suite/util/generic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as vscode from "vscode";
66

77
export const Test_Workspace_Path = vscode.Uri.file(path.resolve(__dirname, "..", "..", "..", "..", "test"));
88
export const Test_Md_File_Path = vscode.Uri.joinPath(Test_Workspace_Path, "test.md");
9+
export const Test_Md_File_Regex_Path = vscode.Uri.joinPath(Test_Workspace_Path, "t*t.md");
910

1011
//#endregion Constant
1112

src/toc.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,22 @@ function getProjectExcludedHeadings(doc: TextDocument): readonly Readonly<{ leve
217217
// Convert file system path to VS Code Uri.
218218
if (path.isAbsolute(filePath)) {
219219
entryUri = Uri.file(filePath);
220+
} else if (filePath.includes('*')) {
221+
entryUri = Uri.file(filePath);
220222
} else if (workspaceUri !== undefined) {
221223
entryUri = Uri.joinPath(workspaceUri, filePath);
222224
} else {
223225
continue; // Discard this entry.
224226
}
225227

226228
// If the entry matches the document, read it.
227-
if (entryUri.toString() === docUriString) {
229+
const pattern = entryUri.toString()
230+
.replace('%2A', '*')
231+
.replace('/', '\/')
232+
.replace('.md', '\.md')
233+
.replace('*', '.*');
234+
235+
if (new RegExp(pattern).test(docUriString)) {
228236
if (Array.isArray(configObj[filePath])) {
229237
omittedHeadings.push(...configObj[filePath]);
230238
} else {

0 commit comments

Comments
 (0)