@@ -238,6 +238,55 @@ Describe 'Comment-based help structure' -Tags 'helpQuality' {
238238 $invalidDirectives | Should - BeNullOrEmpty - Because (' invalid help directives found that will break help parsing: {0}' -f ($invalidDirectives -join ' , ' ))
239239 }
240240 }
241+
242+ It ' Should not have comments within multi-line example code blocks for <Name>' {
243+ <#
244+ PlatyPS expects .EXAMPLE blocks to have: code (no comments) → blank line → description.
245+ Comments (lines starting with #) within the code portion cause "Expect Heading" errors
246+ during documentation generation because PlatyPS interprets them incorrectly.
247+ #>
248+ if ($scriptFileRawContent -match ' (?s)<#(.*?)#>' )
249+ {
250+ $helpBlock = $Matches [1 ]
251+
252+ # Find all .EXAMPLE blocks
253+ $exampleMatches = [regex ]::Matches($helpBlock , ' (?s)\.EXAMPLE\s*\r?\n(.*?)(?=\r?\n\s*\.(?:EXAMPLE|PARAMETER|SYNOPSIS|DESCRIPTION|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|ROLE|FUNCTIONALITY)|$)' )
254+
255+ $examplesWithComments = @ ()
256+
257+ foreach ($exampleMatch in $exampleMatches )
258+ {
259+ $exampleContent = $exampleMatch.Groups [1 ].Value
260+ $exampleLines = $exampleContent -split ' \r?\n'
261+
262+ # Find where the description starts (first line after a blank line that follows code)
263+ $inCodeBlock = $true
264+ $foundBlankLine = $false
265+
266+ foreach ($line in $exampleLines )
267+ {
268+ $trimmedLine = $line.Trim ()
269+
270+ if ($inCodeBlock )
271+ {
272+ if ([string ]::IsNullOrEmpty($trimmedLine ))
273+ {
274+ # Blank line - marks end of code block
275+ $foundBlankLine = $true
276+ $inCodeBlock = $false
277+ }
278+ elseif ($trimmedLine -match ' ^#(?!region|endregion)' )
279+ {
280+ # Found a comment in the code block (excluding #region/#endregion)
281+ $examplesWithComments += $trimmedLine
282+ }
283+ }
284+ }
285+ }
286+
287+ $examplesWithComments | Should - BeNullOrEmpty - Because (' comments within example code blocks break PlatyPS documentation generation: {0}' -f ($examplesWithComments -join ' , ' ))
288+ }
289+ }
241290 }
242291}
243292
0 commit comments