-
Notifications
You must be signed in to change notification settings - Fork 8
/
update-func-markdown.ps1
43 lines (37 loc) · 1.61 KB
/
update-func-markdown.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#Requires -Modules platyPS
[CmdletBinding()]
param()
# Update our Markdown function files
$files = Update-MarkdownHelp .\docs\Functions\ -AlphabeticParamsOrder
# Un-capitalize the section names and add 'powershell' tag to syntax code blocks
$files | ForEach-Object {
$inSyntax = $false
$inCodeBlock = $false
$markdown = $_ | Get-Content | ForEach-Object {
if ($_ -eq '## SYNOPSIS') { '## Synopsis' }
elseif ($_ -eq '## SYNTAX') { '## Syntax'; $inSyntax = $true }
elseif ($_ -eq '## DESCRIPTION') { '## Description'; $inSyntax = $false }
elseif ($_ -eq '## EXAMPLES') { '## Examples' }
elseif ($_ -eq '## PARAMETERS') { '## Parameters' }
elseif ($_ -eq '## INPUTS') { '## Inputs' }
elseif ($_ -eq '## OUTPUTS') { '## Outputs' }
elseif ($_ -eq '## NOTES') { '## Notes' }
elseif ($_ -eq '## RELATED LINKS') { '## Related Links' }
elseif ($inSyntax -and -not $inCodeBlock -and $_ -eq '```') {
$inCodeBlock = $true
'```powershell'
}
elseif ($inSyntax -and $inCodeBlock -and $_ -eq '```') {
$inCodeBlock = $false
$_
}
else { $_ }
}
$markdown | Out-File $_.FullName -Encoding utf8 -Force
}
# Remove empty sections
$files | ForEach-Object {
$raw = $_ | Get-Content -Raw
$markdown = ($raw -replace '## Inputs\r\n\r\n## ','## ' -replace '## Outputs\r\n\r\n## ','## ' -replace '## Notes\r\n\r\n## ','## ').Trim()
$markdown | Out-File $_.FullName -Encoding utf8 -Force
}