diff --git a/CHANGELOG.md b/CHANGELOG.md index d0502bb..3ec4107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.9.8: + +* Format-RichText now supports -Hyperlink (Fixes #93) +* Format-RichText now outputs a single string (Fixes #95) + +--- + ## 1.9.7: * Format-RichText now unbolds bright colors (Fixes #88) * Now Blogging with GitPub (Fixes #89) diff --git a/EZOut.format.ps1xml b/EZOut.format.ps1xml index 9a5f261..eb0d3ad 100644 --- a/EZOut.format.ps1xml +++ b/EZOut.format.ps1xml @@ -1,5 +1,5 @@ - + @@ -984,12 +984,13 @@ if ($Request -or $Host.UI.SupportsHTML) { if (-not ($canUseANSI -or $canUseHTML)) { return $false} return $true })] + [OutputType([string])] param( # The input object [Parameter(ValueFromPipeline)] [PSObject] $InputObject, - + # The foreground color [string]$ForegroundColor, @@ -1024,6 +1025,12 @@ if ($Request -or $Host.UI.SupportsHTML) { # If set, will invert text [switch]$Invert, + + # If provided, will create a hyperlink to a given uri + [Alias('Hyperlink', 'Href')] + [uri] + $Link, + # If set, will not clear formatting [switch]$NoClear ) @@ -1039,8 +1046,10 @@ if ($Request -or $Host.UI.SupportsHTML) { $standardColors = 'Black', 'Red', 'Green', 'Yellow', 'Blue','Magenta', 'Cyan', 'White' $brightColors = 'BrightBlack', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue','BrightMagenta', 'BrightCyan', 'BrightWhite' + $allOutput = @() + $n =0 - $cssClasses = @() + $cssClasses = @() $colorAttributes = @(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) { $n++ @@ -1217,6 +1226,17 @@ if ($Request -or $Host.UI.SupportsHTML) { if ($canUseHTML) { "border-bottom: 3px double;"} elseif ($canUseANSI) {'' +$esc + "[21m" } } + + if ($Hyperlink) { + if ($canUseHTML) { + # Hyperlinks need to be a nested element + # so we will not add it to style attributes for HTML + } + elseif ($canUseANSI) { + # For ANSI, + '' + $esc + ']8m;;' + $Hyperlink + $esc + '\' + } + } ) @@ -1226,61 +1246,76 @@ if ($Request -or $Host.UI.SupportsHTML) { if ($styleAttributes) { " style='$($styleAttributes -join ';')'"} )$( if ($cssClasses) { " class='$($cssClasses -join ' ')'"} - )>" + )>" + $( + if ($Hyperlink) { + "<a href='$hyperLink'>" + } + ) } elseif ($canUseANSI) { $styleAttributes -join '' } } process { - if ($header) { - "$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim() - } - elseif ($inputObject) { - ($inputObject | Out-String).Trim() - } + $allOutput += + if ($header) { + "$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim() + } + elseif ($inputObject) { + ($inputObject | Out-String).Trim() + } } end { if (-not $NoClear) { - if ($canUseHTML) { - "</span>" - } - elseif ($canUseANSI) { - if ($Bold -or $Faint -or $colorAttributes -match '\[1;') { - "$esc[22m" - } - if ($Italic) { - "$esc[23m" - } - if ($Underline -or $doubleUnderline) { - "$esc[24m" - } - if ($Blink) { - "$esc[25m" - } - if ($Invert) { - "$esc[27m" - } - if ($hide) { - "$esc[28m" - } - if ($Strikethru) { - "$esc[29m" - } - if ($ForegroundColor) { - "$esc[39m" - } - if ($BackgroundColor) { - "$esc[49m" + $allOutput += + if ($canUseHTML) { + if ($Hyperlink) { + "</a>" + } + "</span>" } - - if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) { - '' + $esc + '[0m' + elseif ($canUseANSI) { + if ($Bold -or $Faint -or $colorAttributes -match '\[1;') { + "$esc[22m" + } + if ($Italic) { + "$esc[23m" + } + if ($Underline -or $doubleUnderline) { + "$esc[24m" + } + if ($Blink) { + "$esc[25m" + } + if ($Invert) { + "$esc[27m" + } + if ($hide) { + "$esc[28m" + } + if ($Strikethru) { + "$esc[29m" + } + if ($ForegroundColor) { + "$esc[39m" + } + if ($BackgroundColor) { + "$esc[49m" + } + + if ($Hyperlink) { + "$esc]8;;$esc\" + } + + if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) { + '' + $esc + '[0m' + } } - } } + + $allOutput -join '' } @@ -1615,6 +1650,7 @@ $BackgroundColor # If set, will create a link. The -InputObject will be used as the link content [Parameter(ValueFromPipelineByPropertyName)] + [Alias('Hyperlink', 'Href')] [string] $Link, diff --git a/EZOut.psd1 b/EZOut.psd1 index adfae1d..8530b21 100644 --- a/EZOut.psd1 +++ b/EZOut.psd1 @@ -1,6 +1,6 @@ @{ ModuleToProcess = 'EZOut.psm1' - ModuleVersion = '1.9.7' + ModuleVersion = '1.9.8' GUID = 'cef786f0-8a0b-4a5d-a2c6-b433095354cd' Author = 'James Brundage' CompanyName = 'Start-Automating' @@ -65,6 +65,14 @@ Tags = '.ps1xml', 'Format','Output','Types', 'Colorized' ReleaseNotes = @' +## 1.9.8: + +* Format-RichText now supports -Hyperlink (Fixes #93) +* Format-RichText now outputs a single string (Fixes #95) + +--- + + ## 1.9.7: * Format-RichText now unbolds bright colors (Fixes #88) * Now Blogging with GitPub (Fixes #89) diff --git a/Format-Markdown.ps1 b/Format-Markdown.ps1 index 1f06189..1d3e13a 100644 --- a/Format-Markdown.ps1 +++ b/Format-Markdown.ps1 @@ -57,6 +57,7 @@ function Format-Markdown # If set, will create a link. The -InputObject will be used as the link content [Parameter(ValueFromPipelineByPropertyName)] + [Alias('Hyperlink', 'Href')] [string] $Link, diff --git a/Format-RichText.ps1 b/Format-RichText.ps1 index 0f6356a..2cc00eb 100644 --- a/Format-RichText.ps1 +++ b/Format-RichText.ps1 @@ -22,12 +22,13 @@ function Format-RichText if (-not ($canUseANSI -or $canUseHTML)) { return $false} return $true })] + [OutputType([string])] param( # The input object [Parameter(ValueFromPipeline)] [PSObject] $InputObject, - + # The foreground color [string]$ForegroundColor, @@ -62,6 +63,12 @@ function Format-RichText # If set, will invert text [switch]$Invert, + + # If provided, will create a hyperlink to a given uri + [Alias('Hyperlink', 'Href')] + [uri] + $Link, + # If set, will not clear formatting [switch]$NoClear ) @@ -77,8 +84,10 @@ function Format-RichText $standardColors = 'Black', 'Red', 'Green', 'Yellow', 'Blue','Magenta', 'Cyan', 'White' $brightColors = 'BrightBlack', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue','BrightMagenta', 'BrightCyan', 'BrightWhite' + $allOutput = @() + $n =0 - $cssClasses = @() + $cssClasses = @() $colorAttributes = @(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) { $n++ @@ -255,6 +264,17 @@ function Format-RichText if ($canUseHTML) { "border-bottom: 3px double;"} elseif ($canUseANSI) {'' +$esc + "[21m" } } + + if ($Hyperlink) { + if ($canUseHTML) { + # Hyperlinks need to be a nested element + # so we will not add it to style attributes for HTML + } + elseif ($canUseANSI) { + # For ANSI, + '' + $esc + ']8m;;' + $Hyperlink + $esc + '\' + } + } ) @@ -264,60 +284,75 @@ function Format-RichText if ($styleAttributes) { " style='$($styleAttributes -join ';')'"} )$( if ($cssClasses) { " class='$($cssClasses -join ' ')'"} - )>" + )>" + $( + if ($Hyperlink) { + "" + } + ) } elseif ($canUseANSI) { $styleAttributes -join '' } } process { - if ($header) { - "$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim() - } - elseif ($inputObject) { - ($inputObject | Out-String).Trim() - } + $allOutput += + if ($header) { + "$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim() + } + elseif ($inputObject) { + ($inputObject | Out-String).Trim() + } } end { if (-not $NoClear) { - if ($canUseHTML) { - "" - } - elseif ($canUseANSI) { - if ($Bold -or $Faint -or $colorAttributes -match '\[1;') { - "$esc[22m" - } - if ($Italic) { - "$esc[23m" - } - if ($Underline -or $doubleUnderline) { - "$esc[24m" - } - if ($Blink) { - "$esc[25m" - } - if ($Invert) { - "$esc[27m" - } - if ($hide) { - "$esc[28m" - } - if ($Strikethru) { - "$esc[29m" - } - if ($ForegroundColor) { - "$esc[39m" - } - if ($BackgroundColor) { - "$esc[49m" + $allOutput += + if ($canUseHTML) { + if ($Hyperlink) { + "" + } + "" } - - if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) { - '' + $esc + '[0m' + elseif ($canUseANSI) { + if ($Bold -or $Faint -or $colorAttributes -match '\[1;') { + "$esc[22m" + } + if ($Italic) { + "$esc[23m" + } + if ($Underline -or $doubleUnderline) { + "$esc[24m" + } + if ($Blink) { + "$esc[25m" + } + if ($Invert) { + "$esc[27m" + } + if ($hide) { + "$esc[28m" + } + if ($Strikethru) { + "$esc[29m" + } + if ($ForegroundColor) { + "$esc[39m" + } + if ($BackgroundColor) { + "$esc[49m" + } + + if ($Hyperlink) { + "$esc]8;;$esc\" + } + + if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) { + '' + $esc + '[0m' + } } - } } + + $allOutput -join '' } } diff --git a/docs/Assets/EZOut.svg b/docs/Assets/EZOut.svg index a7481e6..31eec34 100644 --- a/docs/Assets/EZOut.svg +++ b/docs/Assets/EZOut.svg @@ -1,4 +1,4 @@ - + @@ -8,4 +8,4 @@ EZ OUT - + \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b99b52c..0c93ea7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.9.8: + +* Format-RichText now supports -Hyperlink (Fixes #93) +* Format-RichText now outputs a single string (Fixes #95) + +--- + ## 1.9.7: * Format-RichText now unbolds bright colors (Fixes #88) * Now Blogging with GitPub (Fixes #89) diff --git a/docs/Format-RichText.md b/docs/Format-RichText.md index 1a1a8d4..936644a 100644 --- a/docs/Format-RichText.md +++ b/docs/Format-RichText.md @@ -218,6 +218,23 @@ If set, will invert text +--- +#### **Link** + +If provided, will create a hyperlink to a given uri + + + +> **Type**: ```[Uri]``` + +> **Required**: false + +> **Position**: 4 + +> **PipelineInput**:false + + + --- #### **NoClear** @@ -235,10 +252,17 @@ If set, will not clear formatting +--- +### Outputs +* [String](https://learn.microsoft.com/en-us/dotnet/api/System.String) + + + + --- ### Syntax ```PowerShell -Format-RichText [[-InputObject] ] [[-ForegroundColor] ] [[-BackgroundColor] ] [-Bold] [-Italic] [-Faint] [-Hide] [-Blink] [-Strikethru] [-Underline] [-DoubleUnderline] [-Invert] [-NoClear] [] +Format-RichText [[-InputObject] ] [[-ForegroundColor] ] [[-BackgroundColor] ] [-Bold] [-Italic] [-Faint] [-Hide] [-Blink] [-Strikethru] [-Underline] [-DoubleUnderline] [-Invert] [[-Link] ] [-NoClear] [] ``` --- ### Notes diff --git a/docs/README.md b/docs/README.md index 874d807..491b576 100644 --- a/docs/README.md +++ b/docs/README.md @@ -163,7 +163,7 @@ Ever wanted to see a nice file tree in PowerShell? With EZOut, it's a snap. Ju ~~~PowerShell Get-Module EZOut | Split-Path | Get-ChildItem | Format-Custom ~~~ -![File Tree Formatter](/Assets/FileTreeFormatter.gif) +![File Tree Formatter](Assets/FileTreeFormatter.gif) ##### Colorized XML Formatter Wish you could see more of any XML node you're working with? EZOut ships with a colorized XML formatter! (colors are supported in PowerShell.exe and pwsh.exe, but not in the PowerShell ISE) @@ -194,5 +194,5 @@ Get-Module EZOut | Format-Custom - - + +