Created
June 7, 2024 19:27
-
-
Save ninmonkey/d8aabe6c62ac35b94c16de0400005677 to your computer and use it in GitHub Desktop.
Which Verbs to Use Question.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter MdFormat-EscapePath { | |
<# | |
.SYNOPSIS | |
make safe markdown style links. convert paths to work as urls and console clickable urls like: <file:///{0}>' | |
.example | |
> 'dir\some Item.md' | MdFormat-EscapePath | |
dir/some%20Item.md | |
#> | |
$_ -replace ' ', '%20' -replace '\\', '/' | |
} | |
function MdFormat-Link { | |
<# | |
.SYNOPSIS | |
format a single markdown url with a name and value | |
.EXAMPLE | |
Pwsh> MdFormat-Link -Name 'go to' -Url 'some Item.md' | |
[go to](some Item.md) | |
MdFormat-Link -Name 'go to' -Url 'dir\some Item.md' -AlwaysEscapeUrlPath | |
[go to](dir/some%20Item.md) | |
#> | |
param( | |
[Parameter(Mandatory)] | |
[string]$Name, | |
[Parameter(Mandatory)] | |
[string]$Url, | |
[Alias('EscapePath')] | |
[switch]$AlwaysEscapeUrlPath, | |
[Alias('EscapeName')] | |
[switch]$AlwaysEscapeKey | |
) | |
$maybeEscapedPath = | |
if( -not $AlwaysEscapeUrlPath ) { | |
$url | |
} else { | |
$url | MdFormat-EscapePath | |
} | |
$maybeEscapedName = | |
if( -not $AlwaysEscapeKey ) { | |
$Name | |
} else { | |
$Name -replace '\(', '\(' -replace '\)', '\)' -replace '\[', '\[' -replace '\]', '\]' | |
} | |
[string] $rendMdLink = @( | |
'[', | |
$maybeEscapedName, | |
']', '(', | |
$maybeEscapedPath | |
')' | |
) -join '' | |
$rendMdLink | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment