Skip to content

Commit

Permalink
Merge pull request #8 from FlorianStadlberger/patch-2
Browse files Browse the repository at this point in the history
#10806 - Fix MarkdownLinkChecker
  • Loading branch information
StefanKert committed May 21, 2019
2 parents 5b53e9f + 71fce6f commit f352607
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ steps:

- task: NodeTool@0
inputs:
versionSpec: '8.x'
checkLatest: true
displayName: 'Install Node.js'

- script: 'npm install -g markdown-link-check'
Expand Down
49 changes: 31 additions & 18 deletions scripts/MarkdownLinkCheck.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$excludedUris = @(
$excludedUris = @(
"https://signaturcloud.fiskaltrust.at",
"https://signaturcloud.fiskaltrust.fr",
"https://helipad.fiskaltrust.cloud",
Expand All @@ -9,34 +9,47 @@ function ContainsExcludedUri($line) {
return $null -ne ($excludedUris | Where-Object { $line -match $_ });
}

function AddError($res, $i) {
$global:errors += ,"$($res[1])`n$($res[$i])`n";
}

function CheckFile($file) {
# get string array [0]is empty [1]Filename [2+]Links + Status
($res = markdown-link-check -v $file) 2> $null

for ($i = 2; $i -le $res.Count - 1; $i++) {
if (ContainsExcludedUri $res[$i]) {
$res[$i] + " is an excluded url."
}
else{
# check if HTML Status beginns with 2 (success)
# `u{2192} = → https://www.fileformat.info/info/unicode/char/2192/index.htm
($res[$i] -match "\u2192 Status: .") > $null
if($Matches.Length -gt 0){
if ($Matches[0][$matches[0].Length - 1] -ne "2")
{
AddError $res $i
}
}
}
}
}


if (!(Get-Command "node" -errorAction SilentlyContinue) -And !(Get-Command "markdown-link-check" -errorAction SilentlyContinue)) {
throw "This script requires node.js and the package markdown-link-check!"
}

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

$files = Get-ChildItem -Path *.md -Recurse
$errors = @()
$global:errors = @()

foreach ($file in $files) {
($res = markdown-link-check -v $file) 2> $null
$text = [system.String]::Join("`n", $res)
if ($text.Contains("")) {
for ($i = 0; $i -le $res.Count - 1; $i++) {
if ($res[$i].Contains("") -and -not (ContainsExcludedUri $res[$i])) {
# check if HTML Status beginns with 2 (success)
$res[$i] -match '→ Status: .';
if ($Matches[0][$matches[0].Length - 1] -eq '2') {
continue;
}
else {
$errors += "$($res[1])`n$($res[$i])`n";
}
}
}
}
CheckFile($file);
}

if ($errors.Count -ge 1) {
throw $errors;
}

0 comments on commit f352607

Please sign in to comment.