-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-Text strings ignore '_' underscore character. #30
Comments
Actually, they don't ignore it, but in my opinion, they try to convert it to markdown. Teams support basic markdown. |
I can see in issue jenkinsci/office-365-connector-plugin#82 someone proposed using ticks facts:
- name: "With back ticks"
value: "`{{ this_is_it }}`" Try it out. |
New-AdaptiveCard -Uri $Env:TEAMSPESTERID -VerticalContentAlignment center {
New-AdaptiveColumnSet {
New-AdaptiveColumn {
New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card _Title_ 1' -Color Warning
New-AdaptiveTextBlock -Size 'Medium' -Text "Test Card \_Title_ 1" -Color Warning # This works
New-AdaptiveTextBlock -Size 'Medium' -Text "Test Card \_Title\_ 1" -Color Warning # This works
$Text = "Test Card _Title_ 1" -replace '_','\_'
New-AdaptiveTextBlock -Size 'Medium' -Text $Text -Color Warning # This works
}
}
} -Verbose So potentially we could add a switch called -EscapeMarkdown which would find all possible options that markdown triggers on and have it automatically fix it for a user. For now, my suggestion is to simply use the replacement proposed. |
Good call.. I wrote this function to fix this... #Region Invoke-EscapeCharacters
Function Invoke-EscapeCharacters() {
[CmdletBinding()]
Param(
[Parameter()]
[Char] $Character,
[Parameter(Mandatory)]
[System.String] $InputString
)
Process {
[System.String] $Character = $Character.ToString()
$InputString.Replace($Character, "\$Character")
}
}
#EndRegion Invoke-EscapeCharacters My code looks something like this for now... $PoolName = "App_Pool_01"
$SectionParams = @{
ActivityTitle = "**Application Pool Recycle**"
ActivitySubtitle = "@$env:USERNAME - $(Get-Date)"
ActivityText = (Invoke-EscapeCharacters -Character _ -InputString "Recycled Pool: $PoolName")
SectionInput = [scriptblock] {
New-TeamsButton -Name 'View Logs' -Type OpenUri -Link 'https://some.link.com'
}
Text = "An app pool recycle of $(Invoke-EscapeCharacters -Character _ -InputString $PoolName) was initiated by $env:USERNAME"
}
Send-TeamsMessage {
New-TeamsSection @SectionParams
} -Uri $Uri -Color DarkSeaGreen -MessageSummary 'Pool Recycle' |
You don't need to do this inside Text. You can do it for the whole text. That is my point. As long as you don't plan using markdown you can escape all |
How exactly would you do this for the whole Text at once? o.O |
Using your function and example: Function Invoke-EscapeCharacters() {
[CmdletBinding()]
Param(
[Parameter()]
[Char] $Character,
[Parameter(Mandatory)]
[System.String] $InputString
)
Process {
[System.String] $Character = $Character.ToString()
$InputString.Replace($Character, "\$Character")
}
}
#EndRegion Invoke-EscapeCharacters
$PoolName = "App_Pool_01"
$SectionParams = @{
ActivityTitle = "**Application Pool Recycle**"
ActivitySubtitle = "@$env:USERNAME - $(Get-Date)"
ActivityText = (Invoke-EscapeCharacters -Character _ -InputString "Recycled Pool: $PoolName")
SectionInput = [scriptblock] {
New-TeamsButton -Name 'View Logs' -Type OpenUri -Link 'https://some.link.com'
}
Text = Invoke-EscapeCharacters -Character _ -InputString "An app pool recycle of $PoolName was initiated by $env:USERNAME"
}
Send-TeamsMessage {
New-TeamsSection @SectionParams
} -Uri $Uri -Color DarkSeaGreen -MessageSummary 'Pool Recycle' In other words it would be possible to easily extend all text functions to turn off Markdown. In theory it would be possible to "disable" markdown on Send-TeamsMessage level as well - I guess. I hope someone will try to PR this. Otherwise if I will have a need for it I'll fix it myself. |
When including the underscore character in any -Text value, the underscores are replaced with null space.
Example:
You can see in the following screenshot that it was removed the underscores from the app pool names.
The text was updated successfully, but these errors were encountered: