-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHelpOut.types.ps1xml
More file actions
303 lines (276 loc) · 8.85 KB
/
HelpOut.types.ps1xml
File metadata and controls
303 lines (276 loc) · 8.85 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>HelpInfo</Name>
<Members>
<AliasProperty>
<Name>Notes</Name>
<ReferencedMemberName>Note</ReferencedMemberName>
</AliasProperty>
<ScriptMethod>
<Name>SaveJson</Name>
<Script>
<#
.SYNOPSIS
Saves a Help Topic as json
.DESCRIPTION
Saves a Help Topic to a json file.
.NOTES
This will not save to files that have illegal names on Windows.
.EXAMPLE
(Get-MarkdownHelp Get-MarkdownHelp).SaveJson(".\test.json")
.LINK
HelpInfo.ToJson
#>
param(
# The path to the file.
# If this does not exist it will be created.
[string]
$FilePath
)
$illegalCharacters = @('<', '>', '|', '?', '*', ':')
$illegalCharacterRegex = '[' + ($illegalCharacters | Foreach-Object { [regex]::Escape($_) }) + ']'
$illegalCharacterReadable = ($illegalCharacters | Foreach-Object { "`"$_`"" }) -join ', '
$filePathWithoutQualifier = Split-Path $filePath -NoQualifier
if ($filePathWithoutQualifier -match $illegalCharacterRegex) {
Write-Warning "Will not .Save to $filePath, because that path will not be readable on all operating systems. It cannot contain any of the characters $illegalCharacterReadable."
return
}
New-Item -ItemType File -Path $FilePath -Force -Value $this.ToJson()
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>ToJson</Name>
<Script>
<#
.SYNOPSIS
Convert HelpInfo to json
.DESCRIPTION
Converts a HelpInfo object to a JSON representation of the object.
.EXAMPLE
(Get-Help Get-Help).ToJson()
#>
param()
$helpObject = $this
[Ordered]@{
Synopsis = $helpObject.Synopsis
Description = $helpObject.Description.text -join ([Environment]::NewLine * 2)
Parameters = @(foreach ($parameter in $helpObject.Parameters) {
[Ordered]@{
Name = $parameter.Name
Type = $parameter.Type.Name
Description = $parameter.Description.text -join ([Environment]::NewLine * 2)
Required = $parameter.Required -match $true
Position = if ($null -ne ($parameter.Position -as [int])) {
$parameter.Position -as [int]
} else {
-1
}
Aliases = $parameter.Aliases
DefaultValue = $parameter.DefaultValue
Globbing = $parameter.Globbing -match $true
PipelineInput = $parameter.PipelineInput
variableLength = $parameter.variableLength -match $true
}
})
Notes = @($helpObject.alertSet.alert.text)
CommandType = $helpObject.Category
Component = @($helpObject.Component)
Inputs = @(
$helpObject.InputTypes.InputType.Type.Name
)
Outputs = @(
$helpObject.ReturnValues.ReturnValue.Type.Name
)
Links = @(
foreach ($relLink in $this.RelatedLinks.navigationLink) {
if ($relLink.uri) {
$relLink.uri
} else {
$relLink.text
}
}
)
Examples = @(
foreach ($example in $helpObject.Examples.Example) {
# Combine the code and remarks
$exampleLines =
@(
$example.Code
foreach ($remark in $example.Remarks.text) {
if (-not $remark) { continue }
$remark
}
) -join ([Environment]::NewLine) -split '(?>\r\n|\n)' # and split into lines
# Anything until the first non-comment line is a markdown predicate to the example
$nonCommentLine = $false
$markdownLines = @()
# Go thru each line in the example as part of a loop
$codeBlock = @(foreach ($exampleLine in $exampleLines) {
if ($exampleLine -match '^\#' -and -not $nonCommentLine) {
$markdownLines += $exampleLine -replace '^\#' -replace '^\s+'
} else {
$nonCommentLine = $true
$exampleLine
}
}) -join [Environment]::NewLine
[Ordered]@{
Title = ($example.Title -replace '^[-\s]+' -replace '[-\s]+$')
Markdown = $markdownLines -join [Environment]::NewLine
Code = $codeBlock
}
}
)
} | ConvertTo-Json -Depth 10
</Script>
</ScriptMethod>
<ScriptProperty>
<Name>Note</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets HelpInfo notes
.DESCRIPTION
Gets the `Notes` section of a HelpInfo object.
.EXAMPLE
(Get-Help Get-Help).Note
#>
param()
@($this.alertSet.alert.text)
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
<Type>
<Name>PowerShell.Markdown.Help</Name>
<Members>
<ScriptMethod>
<Name>HideSection</Name>
<Script>
<#
.SYNOPSIS
Hides sections of markdown help
.DESCRIPTION
Hides sections of a command's markdown help.
#>
param(
# One or more section names.
[ValidateSet('Name','Synopsis','Description','RelatedLinks','Examples','Parameters','Inputs','Outputs','Notes','Story','Syntax')]
[Alias('SectionName')]
[string[]]
$SectionNames
)
$skipSectionNames = @($This.HideSections)
foreach ($SectionName in $SectionNames) {
if ($skipSectionNames -notcontains $SectionName) {
$skipSectionNames += $SectionName
}
}
$this |
Add-Member NoteProperty HideSections $skipSectionNames -Force
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>Save</Name>
<Script>
<#
.SYNOPSIS
Saves a Markdown Help Topic
.DESCRIPTION
Saves a Markdown Help Topic to a file.
.NOTES
This will not save to files that have illegal names on Windows.
.EXAMPLE
(Get-MarkdownHelp Get-MarkdownHelp).Save(".\test.md")
.LINK
PowerShell.Markdown.Help.ToMarkdown
#>
param(
# The path to the file.
# If this does not exist it will be created.
[string]
$FilePath,
# An optional view.
# This would need to be declared in a .format.ps1xml file by another loaded module.
[string]
$View = 'PowerShell.Markdown.Help'
)
$illegalCharacters = @('<', '>', '|', '?', '*', ':')
$illegalCharacterRegex = '[' + ($illegalCharacters | Foreach-Object { [regex]::Escape($_) }) + ']'
$illegalCharacterReadable = ($illegalCharacters | Foreach-Object { "`"$_`"" }) -join ', '
$filePathWithoutQualifier = Split-Path $filePath -NoQualifier
if ($filePathWithoutQualifier -match $illegalCharacterRegex) {
Write-Warning "Will not .Save to $filePath, because that path will not be readable on all operating systems. It cannot contain any of the characters $illegalCharacterReadable."
return
}
if (-not (Test-Path $FilePath)) {
$createdFile = New-Item -ItemType File -Path $FilePath -Force
if (-not $createdFile) { return }
}
Set-Content -Path $filePath -Value $this.ToMarkdown($view)
if ($?) {
Get-Item -Path $FilePath
}
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>ShowSection</Name>
<Script>
<#
.SYNOPSIS
Shows sections of markdown help
.DESCRIPTION
Shows sections of a command's markdown help.
#>
param(
# One or more section names
[ValidateSet('Name','Synopsis','Description','RelatedLinks','Examples','Parameters','Inputs','Outputs','Notes','Story','Syntax')]
[Alias('SectionName')]
[string[]]
$SectionNames
)
$skipSectionNames = @($This.HideSections)
foreach ($SectionName in $SectionNames) {
if ($skipSectionNames -contains $SectionName) {
$skipSectionNames = @($skipSectionNames -ne $SectionName)
}
}
$this |
Add-Member NoteProperty HideSections $skipSectionNames -Force
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>ToMarkdown</Name>
<Script>
<#
.SYNOPSIS
Returns this topic as a markdown string
.DESCRIPTION
Returns the content of this help topic as a markdown string.
.EXAMPLE
(Get-MarkDownHelp Get-MarkDownHelp).ToMarkdown()
#>
param(
# An optional view.
# This would need to be declared in a .format.ps1xml file by another loaded module.
[string]
$View = 'PowerShell.Markdown.Help'
)
($this |
Format-Custom -View $View |
Out-String -Width 1mb).Trim()
</Script>
</ScriptMethod>
<NoteProperty>
<Name>README</Name>
<Value>This PSType is used to transform help for a command into Markdown.
To get help for any command as markdown, use `Get-MarkdownHelp`.
~~~PowerShell
$MarkdownHelp = Get-MarkdownHelp Get-MarkdownHelp
$MarkdownHelp
~~~</Value>
</NoteProperty>
</Members>
</Type>
</Types>