Skip to content

Instantly share code, notes, and snippets.

@eNeRGy164
Last active February 18, 2017 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eNeRGy164/2bc35ceb31104d7a2d48d2993e92354b to your computer and use it in GitHub Desktop.
Save eNeRGy164/2bc35ceb31104d7a2d48d2993e92354b to your computer and use it in GitHub Desktop.
A PowerShell script that formats the output of the Test-HtmlValidity script. Also support grouped input on the URL property.
<#
.SYNOPSIS
Formats the output of the Test-HtmlValidity script
.DESCRIPTION
Formats the output of the Test-HtmlValidity script. Also support grouped input on the URL property.
.NOTES
Author: Michaël Hompus
License: This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 Generic License.
.PARAMETER Messages
One or more output messages from the HTML validity PowerShell Script.
.LINK
Invoke-RestMethod
https://gist.github.com/eNeRGy164/2bc35ceb31104d7a2d48d2993e92354b
https://gist.github.com/eNeRGy164/ffb410e6dc6acb8610af3e4a1a85437c
.EXAMPLE
Test-HtmlValidity.ps1 -Urls https://blog.hompus.nl/ | .\Format-HtmlValidityOutput.ps1
.EXAMPLE
Test-HtmlValidity.ps1 -Urls https://blog.hompus.nl,https://blog.hompus.nl/about/ | .\Format-HtmlValidityOutput.ps1
.EXAMPLE
Test-HtmlValidity.ps1 -Urls https://blog.hompus.nl,https://blog.hompus.nl/about/ | Group-Object Url | .\Format-HtmlValidityOutput.ps1
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[PSObject[]]
$Messages
)
BEGIN {
if ($null -eq $Messages) {
$Messages = @($input)
}
}
PROCESS {
Function Write-FormattedMessages {
[CmdletBinding()]
param(
[Switch]$IsGrouped = $false,
[Switch]$HideUrl = $false
)
if (-not $IsGrouped -or -not $HideUrl) {
Write-Host -ForegroundColor DarkCyan $_.Url
Write-Host
}
if ($_.Type -eq "error") {
Write-Host -NoNewline -ForegroundColor Red " Error "
} elseif ($_.Type -eq "warning") {
Write-Host -NoNewline -ForegroundColor Yellow " Warning "
} elseif ($_.Type -eq "Valid") {
Write-Host -NoNewline -ForegroundColor Green " Valid "
} else {
Write-Host -NoNewline -ForegroundColor White " Info "
}
if ($_.Type -ne "Valid") {
Write-Host -NoNewline $_.Message
Write-Host -ForegroundColor DarkGray " ($($_.LastLine), $($_.LastColumn))"
$HiliteEnd = ($_.HiliteStart + $_.HiliteLength)
Write-Host -NoNewline " "
for ($i = 0; $i -lt $_.HiliteStart; $i++) {
Write-Host -NoNewline -BackgroundColor DarkBlue $_.Extract[$i]
}
for ($i = $_.HiliteStart; $i -lt $HiliteEnd; $i++) {
Write-Host -NoNewline -BackgroundColor Black -ForegroundColor Yellow $_.Extract[$i]
}
for ($i = $HiliteEnd; $i -lt $_.Extract.Length; $i++) {
Write-Host -NoNewline -BackgroundColor DarkBlue $_.Extract[$i]
}
}
Write-Host
Write-Host
}
if ($Messages.Group -ne $null) {
Write-Host -ForegroundColor DarkCyan $_.Name
Write-Host
$hideUrl = ($_.Name -eq $_.Group[0].url)
$Messages.Group | ForEach-Object { Write-FormattedMessages -IsGrouped -HideUrl:$hideUrl }
} else {
$Messages | ForEach-Object { Write-FormattedMessages }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment