## ConvertTo-DekiContent (aka Convert Help to Html) #################################################################################################### ## Converts the -Full help output to HTML markup for insertion into web pages. #################################################################################################### ## Usage: ## ## foreach($cmd in (gcm -type cmdlet | ? { $_.PsSnapin -like "Microsoft.PowerShell*" })) { ## ## Get-Help $cmd.Name -full | ConvertTo-DekiContent Cmdlet_Help | ## %{ Set-DekiContent "Cmdlet_Help/$($cmd.PSSnapin)/$($cmd.Name)" $_ } ## } ## #################################################################################################### ## History: ## v2.0 - Refactoring of markup and code by Joel "Jaykul" Bennett to avoid line-wrapping, and 'pre' ## blocks in the code and to format the parameters and examples more like the originals. ## v1.0 - Original version by http://blogs.vmware.com/vipowershell/2007/09/new-htmlhelp.html #################################################################################################### #Import System.Web in order to use HtmlEncode functionality [System.Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null ## Get-HtmlHelp - A Helper function for generating help: ## Usage: Get-HtmlHelp Get-* function Get-HtmlHelp { param([string[]]$commands, [string]$baseUrl) $commands | Get-Command -type Cmdlet -EA "SilentlyContinue" | get-help -Full | ConvertTo-DekiContent $baseUrl } function ConvertTo-DekiContent { param($baseUrl) PROCESS { if($_ -and ($_.PSObject.TypeNames -contains "MamlCommandHelpInfo#FullView")) { $help = $_ # Name isn't needed, since this is going as the body, but ... # $data = "
| Required? | $(encode($param.Required)) |
|---|---|
| Position? | $(encode($param.Position)) |
| Default value? | $(encode($param.defaultValue)) |
| Accept pipeline input? | $(encode($param.pipelineInput)) |
| Accept wildcard characters? | $(encode($param.globbing)) |
PS> $(encode($example.code))"
$data += "$($example.remarks | out-string -width ([int]::MaxValue) | Out-HtmlPara)
" } # $data += "" write-output $data } else { Write-Error "Can only process -Full view help output" } }} function encode($str) { begin{ if($str){ $str.split("`n") | encode } } process{ if($_){ [System.Web.HttpUtility]::HtmlEncode($_).Trim() } } } function trim($str) { begin{ if($str){ $str.Trim() } } process{ if($_){ $_.Trim() } } } function split($Separator="`n",$inputObject) { begin{ if($inputObject){ $inputObject | split $Separator } } process{ if($_){ [regex]::Split($_,$Separator) | ? {$_.Length} } } } function join($Separator=$ofs,$inputObject) { begin{ if($inputObject){ [string]::Join($Separator,$inputObject) } else { $array =@() }} process{ if($_){ $array += $_ } } end{ if($array.Length) { [string]::Join($Separator,$array) } } } function Out-HtmlPara { process{if($_){"$($_ | out-string -width ([int]::MaxValue) | split "\s*`n" | encode | trim | join "
`n")
"}} }