Skip to content

Commit

Permalink
Enhance error handling for Spectre Console markup input in Renderable…
Browse files Browse the repository at this point in the history
…TransformationAttribute
  • Loading branch information
ShaunLawrie committed Oct 23, 2024
1 parent 2d43432 commit 3b6b770
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion PwshSpectreConsole/private/completions/Transformers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ class RenderableTransformationAttribute : ArgumentTransformationAttribute {

# For others just dump them as either strings formatted with markup which are easy to identify by the closing tag [/] or as plain text
if ($InputData -like "*[/]*" -or $InputData -like "*:*:*") {
return [Spectre.Console.Markup]::new($InputData)
try {
$markup = [Spectre.Console.Markup]::new($InputData)
return $markup
} catch {
throw @(
"`n`nYour input includes Spectre Console markup characters (see https://spectreconsole.net/markup).",
"Escape the special characters in the input before using it in a Spectre Console function using the Get-SpectreEscapedText function.",
"",
" e.g. `$myEscapedInput = Get-SpectreEscapedText '$InputData'",
"`n"
) -join "`n"
}
} else {
return [Spectre.Console.Text]::new(($InputData | Out-String -NoNewline))
}
Expand Down

0 comments on commit 3b6b770

Please sign in to comment.