Skip to content

Commit 9c3ba0e

Browse files
authored
Merge pull request #1198 from NeillM/fixlinkchecker
Fix link checker on Windows
2 parents df44382 + a7138a6 commit 9c3ba0e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

.markdownlint/fix-renamed-links.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const {
2828
const path = require('path');
2929
const fs = require('fs');
3030

31-
const rootDir = path.dirname(__dirname);
31+
const rootDir = path.posix.dirname(__dirname);
3232

3333
// A simple regex to capture all links which are not images.
3434
const linkFinder = /(?<!!)(?<description>\[[^\]]*\](?=\((?<target>[^)]*)\)|\[[^\]]*\]))/g;
@@ -67,7 +67,7 @@ const getRenamedFileMapping = (renames) => {
6767
* @param {string} file The file to normalise the location of
6868
* @returns {string} The normalised location
6969
*/
70-
const getNormalisedFile = (file) => `/${path.relative(rootDir, file)}`;
70+
const getNormalisedFile = (file) => `/${path.posix.relative(rootDir, file)}`;
7171

7272
/**
7373
* Get an absolute link relative to the root directory of the project.
@@ -86,10 +86,10 @@ const getNormalisedLink = (file, link) => {
8686
const normalisedFile = getNormalisedFile(file);
8787

8888
// Get the directory that it is in.
89-
const normalisedDir = path.dirname(normalisedFile);
89+
const normalisedDir = path.posix.dirname(normalisedFile);
9090

9191
// Return a link relative to the file that the link was found in.
92-
return path.join(normalisedDir, link);
92+
return path.posix.join(normalisedDir, link);
9393
};
9494

9595
/**
@@ -152,7 +152,7 @@ const findFile = (file) => {
152152
];
153153

154154
for (const filePath of paths) {
155-
const fullPath = path.join(rootDir, filePath);
155+
const fullPath = path.posix.join(rootDir, filePath);
156156
try {
157157
// Allow use of fs.statSync here because it's preferable to asynchronous rule handling for markdownlint.
158158
// eslint-disable-next-line no-restricted-properties
@@ -190,7 +190,7 @@ const getOptimisedLink = (mappings, file, currentLink, forceRelative) => {
190190
// Either the link has changed, or the forceRelative configuration is set.
191191
// Update to point to a relative _file_ if possible.
192192
const updatedFileLink = findFile(updatedLink);
193-
let relativeLink = path.relative(path.dirname(normalisedCurrentFile), updatedFileLink);
193+
let relativeLink = path.posix.relative(path.posix.dirname(normalisedCurrentFile), updatedFileLink);
194194

195195
if (relativeLink.length === 0) {
196196
// This is a link to the current document.

0 commit comments

Comments
 (0)