Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Controls in which column should clicked files open. Refer to [Column values](###

A [regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) used to find the file ID for use in wiki-style links.

### `markdown-links.findFilesGlob`

[Glob pattern](https://code.visualstudio.com/api/references/vscode-api#GlobPattern) used to find files to parse with the Markdown Links extension. Handy in a case that you want only a part of your workspace parsed.

### `markdown-links.graphType`

- `default` (**default**)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
"markdown-links.fileIdRegexp": {
"type": "string",
"default": "\\d{14}",
"description": "Regular extension used to find file IDs. First match of this regex in file contents, excluding [[links]], will be used as the file ID. This file ID can be used for wiki-style links."
"description": "Regular expression used to find file IDs. First match of this regex in file contents, excluding [[links]], will be used as the file ID. This file ID can be used for wiki-style links."
},
"markdown-links.findFilesGlob" : {
"type": "string",
"description": "Glob pattern used to find files to parse with the Markdown Links extension. https://code.visualstudio.com/api/references/vscode-api#GlobPattern",
"examples": ["**/*.md", "notes-folder/*.md"]
},
"markdown-links.autoStart": {
"type": "boolean",
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
filterNonExistingEdges,
getColumnSetting,
getConfiguration,
getFileTypesSetting,
getFindFilesGlob,
} from "./utils";
import { Graph } from "./types";

Expand All @@ -22,7 +22,7 @@ const watch = (
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
vscode.workspace.rootPath,
`**/*{${getFileTypesSetting().join(",")}}`
getFindFilesGlob()
),
false,
false,
Expand Down
8 changes: 2 additions & 6 deletions src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
findLinks,
id,
FILE_ID_REGEXP,
getFileTypesSetting,
getConfiguration,
getTitleMaxLength,
Comment thread
tchayen marked this conversation as resolved.
getFindFilesGlob,
} from "./utils";
import { basename } from "path";

Expand Down Expand Up @@ -100,9 +98,7 @@ export const parseDirectory = async (
) => {
// `findFiles` is used here since it respects files excluded by either the
// global or workspace level files.exclude config option.
const files = await vscode.workspace.findFiles(
`**/*{${(getFileTypesSetting() as string[]).map((f) => `.${f}`).join(",")}}`
);
const files = await vscode.workspace.findFiles(getFindFilesGlob());

const promises: Promise<void>[] = [];

Expand Down
19 changes: 15 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const findTitle = (ast: MarkdownNode): string | null => {
child.children &&
child.children.length > 0
) {
let title = child.children[0].value!
let title = child.children[0].value!;

const titleMaxLength = getTitleMaxLength();
if (titleMaxLength > 0 && title.length > titleMaxLength) {
Expand Down Expand Up @@ -83,7 +83,7 @@ const settingToValue: { [key: string]: vscode.ViewColumn | undefined } = {

export const getTitleMaxLength = () => {
return getConfiguration("titleMaxLength");
}
};

export const getColumnSetting = (key: string) => {
const column = getConfiguration(key);
Expand All @@ -102,9 +102,20 @@ export const getFileIdRegexp = () => {

export const FILE_ID_REGEXP = getFileIdRegexp();

export const getFileTypesSetting = () => {
export const getFindFilesGlob = (): string => {
const configFileTypes: string[] = getConfiguration("fileTypes");
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably either deprecate this search option or include it to package.json and README.

const findFilesGlob: string = getConfiguration("findFilesGlob");
if (findFilesGlob) {
if (configFileTypes) {
vscode.window.showWarningMessage(
"You have both fileTypes and findFilesGlob settings defined, findFilesGlob is taking precedence."
);
}
return findFilesGlob;
}
const DEFAULT_VALUE = ["md"];
return getConfiguration("fileTypes") || DEFAULT_VALUE;
const fileTypes = configFileTypes || DEFAULT_VALUE;
return `**/*{${fileTypes.map((f) => `.${f}`).join(",")}}`;
};

export const getDot = (graph: Graph) => `digraph g {
Expand Down