Skip to content

Commit 48f4d80

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/express-4.19.2
2 parents 7b963c2 + dd76386 commit 48f4d80

11 files changed

+414
-316
lines changed

.eslintrc.js

-21
This file was deleted.

.github/workflows/ci.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
1212
strategy:
1313
fail-fast: false
1414
matrix:
15+
os:
16+
- ubuntu-latest
17+
- windows-latest
18+
- macos-latest
1519
node-version:
1620
- 18
1721
- 20
@@ -20,9 +24,9 @@ jobs:
2024
env:
2125
NODE_OPTIONS: '--dns-result-order=ipv4first'
2226
steps:
23-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2428
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v3
29+
uses: actions/setup-node@v4
2630
with:
2731
node-version: ${{ matrix.node-version }}
2832
cache: npm

.github/workflows/release.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
- uses: actions/setup-node@v3
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
1313
with:
1414
node-version: '18.x'
1515
registry-url: 'https://registry.npmjs.org'
@@ -35,7 +35,7 @@ jobs:
3535
| sed -e 's/refs\/tags\///g' \
3636
| sed -E 's/v?([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?/\1.\2.\3\4\,\1.\2\4\,\1\4/g')" >> $GITHUB_ENV
3737
- name: "Repo: Checkout"
38-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
3939
- name: "Docker: Build & Publish"
4040
id: build
4141
uses: elgohr/Publish-Docker-Github-Action@v5

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ To run as a [pre-commit hook](https://pre-commit.com):
5050
args: [-q]
5151
```
5252

53+
## Run in a GitLab pipeline
54+
55+
```yaml
56+
linkchecker:
57+
stage: test
58+
image:
59+
name: ghcr.io/tcort/markdown-link-check:3.11.2
60+
entrypoint: ["/bin/sh", "-c"]
61+
script:
62+
- find . -name \*.md -print0 | xargs -0 -n1 markdown-link-check
63+
rules:
64+
- changes:
65+
- "**/*.md"
66+
```
67+
5368
## Run in other tools
5469
5570
- [Mega-Linter](https://megalinter.io/latest/): Linters aggregator [including markdown-link-check](https://megalinter.io/latest/descriptors/markdown_markdown_link_check/)

eslint.config.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
4+
export default [
5+
js.configs.recommended,
6+
{
7+
languageOptions: {
8+
globals: {
9+
...globals.node,
10+
},
11+
parserOptions: {
12+
ecmaVersion: "latest",
13+
moduleType: "commonjs"
14+
},
15+
},
16+
},
17+
{
18+
files: ["test/*.js"],
19+
languageOptions: {
20+
globals: {
21+
...globals.node,
22+
...globals.mocha,
23+
},
24+
},
25+
},
26+
];

index.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ function performSpecialReplacements(str, opts) {
4343
return str;
4444
}
4545

46+
function extractSections(markdown) {
47+
// First remove code blocks.
48+
markdown = markdown.replace(/^```[\S\s]+?^```$/mg, '');
49+
50+
const sectionTitles = markdown.match(/^#+ .*$/gm) || [];
51+
52+
const sections = sectionTitles.map(section =>
53+
section.replace(/^\W+/, '').replace(/\W+$/, '').replace(/[^\w\s-]+/g, '').replace(/\s+/g, '-').toLowerCase()
54+
);
55+
56+
var uniq = {};
57+
for (var section of sections) {
58+
if (section in uniq) {
59+
uniq[section]++;
60+
section = section + '-' + uniq[section];
61+
}
62+
uniq[section] = 0;
63+
}
64+
const uniqueSections = Object.keys(uniq) ?? [];
65+
66+
return uniqueSections;
67+
}
68+
4669
module.exports = function markdownLinkCheck(markdown, opts, callback) {
4770
if (arguments.length === 2 && typeof opts === 'function') {
4871
// optional 'opts' not supplied.
@@ -62,6 +85,7 @@ module.exports = function markdownLinkCheck(markdown, opts, callback) {
6285
}
6386

6487
const links = markdownLinkExtractor(markdown);
88+
const sections = extractSections(markdown);
6589
const linksCollection = _.uniq(links);
6690
const bar = (opts.showProgressBar) ?
6791
new ProgressBar('Checking... [:bar] :percent', {
@@ -114,8 +138,24 @@ module.exports = function markdownLinkCheck(markdown, opts, callback) {
114138
}
115139
}
116140

117-
linkCheck(link, opts, function (err, result) {
141+
let sectionLink = null;
118142

143+
if (link.startsWith('#')) {
144+
sectionLink = link;
145+
}
146+
else if ('baseUrl' in opts && link.startsWith(opts.baseUrl)) {
147+
if (link.substring(opts.baseUrl.length).match(/^\/*#/)) {
148+
sectionLink = link.replace(/^[^#]+/, '');
149+
}
150+
}
151+
152+
if (sectionLink) {
153+
const result = new LinkCheckResult(opts, sectionLink, sections.includes(sectionLink.substring(1)) ? 200 : 404, undefined);
154+
callback(null, result);
155+
return;
156+
}
157+
158+
linkCheck(link, opts, function (err, result) {
119159
if (opts.showProgressBar) {
120160
bar.tick();
121161
}

markdown-link-check

+13-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ function getInputs() {
100100
continue;
101101
}
102102

103-
baseUrl = 'file://' + path.dirname(resolved);
103+
if (process.platform === 'win32') {
104+
baseUrl = 'file://' + path.dirname(resolved).replace(/\\/g, '/');
105+
}
106+
else {
107+
baseUrl = 'file://' + path.dirname(resolved);
108+
}
109+
104110
stream = fs.createReadStream(filenameOrUrl);
105111
}
106112

@@ -124,7 +130,12 @@ function getInputs() {
124130
input.opts.projectBaseUrl = `file://${program.projectBaseUrl}`;
125131
} else {
126132
// set the default projectBaseUrl to the current working directory, so that `{{BASEURL}}` can be resolved to the project root.
127-
input.opts.projectBaseUrl = `file://${process.cwd()}`;
133+
if (process.platform === 'win32') {
134+
input.opts.projectBaseUrl = `file:///${process.cwd().replace(/\\/g, '/')}`;
135+
}
136+
else {
137+
input.opts.projectBaseUrl = `file://${process.cwd()}`;
138+
}
128139
}
129140
}
130141

0 commit comments

Comments
 (0)