-
-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
URL building based on the markdown approach works for most cases. But it doesn't work for cases where the URL itself has brackets in it. The second text won't convert properly.
New-HTML {
New-HTMLText -Text @(
"This is a string with [SomeURL](https://evotec.xyz) and this isn't. "
"This is more complicated [URL](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dn535495(v=ws.11)) with double () and it doesn't work properly "
"More URLs in one line [SomeURL](https://evotec.xyz) and and [SomeURL](https://evotec.xyz)."
)
} -ShowHTMLCode for it is located at:
PSWriteHTML/Public/New-HTMLText.ps1
Lines 139 to 181 in d29c115
| New-HTMLSpanStyle @newSpanTextSplat { | |
| $FindMe = [regex]::Matches($Text[$i], "\[[^\]]+\]\([^)]+\)") | |
| if ($FindMe) { | |
| foreach ($find in $FindMe) { | |
| $LinkName = ([regex]::Match($Find.value, "[^\[]+(?=\])")).Value | |
| $LinkURL = ([regex]::Match($Find.value, "(?<=\().+?(?=\))")).Value | |
| $Link = New-HTMLAnchor -HrefLink $LinkURL -Text $LinkName | |
| $Text[$i] = $Text[$i].Replace($find.value, $Link) | |
| } | |
| $Text[$i] | |
| } else { | |
| # Default | |
| $Text[$i] | |
| } | |
| # Replaces code above -> JustinWGrote made it -> complains go to him | |
| #$markdownRegex = '\[(?<title>[^\]]+)\]\((?<uri>https?.+?)\)[\s\r\n$]' | |
| #$Text[$i] -replace $markdownRegex, '<a href="$2">$1</a>' | |
| <# | |
| if ($Text[$i] -match "\[[^\]]+\]\([^)]+\)") { | |
| # Covers markdown LINK "[somestring](https://evotec.xyz)" | |
| $RegexBrackets1 = [regex] '\[[^\]]+\]\([^)]+\)' | |
| $RegexBrackets1 = [regex] "\[([^\[]*)\]" # catch 'sometstring' | |
| $RegexBrackets2 = [regex] "\(([^\[]*)\)" # catch link | |
| $RegexBrackets3 = [regex] "\[([^\[]*)\)" # catch both somestring and link | |
| $Text1 = $RegexBrackets1.match($Text[$i]).Groups[1].value | |
| #$Text2 = $RegexBrackets2.match($Text[$i]).Groups[1].value | |
| $Text3 = $RegexBrackets3.match($Text[$i]).Groups[0].value | |
| if ($Text1 -ne '' -and $Text2 -ne '') { | |
| $Link = New-HTMLAnchor -HrefLink $Text2 -Text $Text1 | |
| $Text[$i].Replace($Text3, $Link) | |
| } | |
| } else { | |
| # Default | |
| $Text[$i] | |
| # if ($NewLine[$i]) { | |
| # '<br>' | |
| #} | |
| } | |
| #> | |
| } |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed