Skip to content

Commit

Permalink
Merge pull request #96 from StartAutomating/EZ-Hyperlinks
Browse files Browse the repository at this point in the history
EZOut 1.9.8
  • Loading branch information
StartAutomating authored Dec 15, 2022
2 parents 7e3594a + 49cf978 commit aef9cd1
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 94 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
124 changes: 80 additions & 44 deletions EZOut.format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 1.9.8: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Configuration>
<SelectionSets>
<SelectionSet>
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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
)
Expand All @@ -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++
Expand Down Expand Up @@ -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 + '\'
}
}

)

Expand All @@ -1226,61 +1246,76 @@ if ($Request -or $Host.UI.SupportsHTML) {
if ($styleAttributes) { " style='$($styleAttributes -join ';')'"}
)$(
if ($cssClasses) { " class='$($cssClasses -join ' ')'"}
)&gt;"
)&gt;" + $(
if ($Hyperlink) {
"&lt;a href='$hyperLink'&gt;"
}
)
} 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) {
"&lt;/span&gt;"
}
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) {
"&lt;/a&gt;"
}
"&lt;/span&gt;"
}

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 ''
}
</ScriptBlock>
</ExpressionBinding>
Expand Down Expand Up @@ -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,

Expand Down
10 changes: 9 additions & 1 deletion EZOut.psd1
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Format-Markdown.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
Loading

0 comments on commit aef9cd1

Please sign in to comment.