Skip to content

Fix link checker on Windows #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
12 changes: 6 additions & 6 deletions .markdownlint/fix-renamed-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
const path = require('path');
const fs = require('fs');

const rootDir = path.dirname(__dirname);
const rootDir = path.posix.dirname(__dirname);

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

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

// Get the directory that it is in.
const normalisedDir = path.dirname(normalisedFile);
const normalisedDir = path.posix.dirname(normalisedFile);

// Return a link relative to the file that the link was found in.
return path.join(normalisedDir, link);
return path.posix.join(normalisedDir, link);
};

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ const findFile = (file) => {
];

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

if (relativeLink.length === 0) {
// This is a link to the current document.
Expand Down
Loading