Private/Get-AutoLinkText.ps1
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 |
function Get-AutoLinkText { param ( [parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $StringValue, [parameter()][switch] $NewPage ) Write-Log -Message "(Get-AutoLinkText)" -LogFile $logfile $temp = @() $tokens = $StringValue.split(' ') $tokens | ForEach-Object { if ($_.StartsWith('http')) { if ($NewPage) { $temp += "<a href=`"$_`" target=`"blank`">$_</a>" } else { $temp += "<a href=`"$_`">$_</a>" } } elseif ($_.StartsWith('(http') -and $_.EndsWith(')')) { if ($NewPage) { $temp += "(<a href=`"$_`" target=`"blank`">$_</a>)" } else { $temp += "(<a href=`"$_`">$_</a>)" } } elseif ($_.StartsWith('(http') -and $_.EndsWith(').')) { $tx = ($_.Replace('(','')).Replace(').','') if ($NewPage) { $temp += "(<a href=`"$tx`" target=`"blank`">$tx</a>)." } else { $temp += "(<a href=`"$tx`">$tx</a>)." } } else { $temp += $_ } } $temp -join ' ' } |