-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
BeforeAll { | ||
. $PSCommandPath.Replace('.Tests.ps1', '.ps1') | ||
$MDQuoteFile = Join-Path -Path (Split-Path $PSCommandPath -Parent) -ChildPath 'New-MDQuote.ps1' | ||
. $MDQuoteFile | ||
$newLine = [System.Environment]::NewLine | ||
} | ||
Describe -Tag @('MarkdownPS', 'Cmdlet', 'Public') 'New-MDAlert' { | ||
It '-Lines is null' { | ||
{ New-MDAlert -Lines $null } | Should -Throw '*because it is null.*' | ||
} | ||
It '-Lines is empty' { | ||
{ New-MDAlert -Lines @() } | Should -Throw '*because it is an empty array.*' | ||
} | ||
It '-Style out of range' { | ||
{ New-MDAlert -Lines 'Line 1' -Style Unknown } | Should -Throw -ErrorId 'ParameterArgumentValidationError,New-MDAlert' | ||
} | ||
} | ||
Describe -Tag @('MarkdownPS', 'Cmdlet', 'Public', 'New-MDAlert') 'New-MDAlert' { | ||
It '-Lines count is 1 & -Style not specified' { | ||
$expected = '> [!NOTE]' + $newLine + '> Line 1' + $newLine + $newLine | ||
New-MDAlert -Lines 'Line 1' | Should -Be $expected | ||
New-MDAlert -Lines @('Line 1') | Should -Be $expected | ||
'Line 1' | New-MDAlert | Should -Be $expected | ||
@('Line 1') | New-MDAlert | Should -Be $expected | ||
} | ||
It '-Lines count is 2 & -Style not specified' { | ||
$expected = '> [!NOTE]' + $newLine + '> Line 1' + $newLine + '> Line 2' + $newLine + $newLine | ||
# New-MDAlert -Lines @('Line 1', 'Line 2') | Should -Be $expected | ||
@('Line 1', 'Line 2') | New-MDAlert | Should -Be $expected | ||
} | ||
It '-Lines count is 1 & -Style provided' { | ||
$expected = '> [!TIP]' + $newLine + '> Line 1' + $newLine + $newLine | ||
New-MDAlert -Lines 'Line 1' -Style Tip | Should -Be $expected | ||
New-MDAlert -Lines @('Line 1') -Style Tip | Should -Be $expected | ||
'Line 1' | New-MDAlert -Style Tip | Should -Be $expected | ||
@('Line 1') | New-MDAlert -Style Tip | Should -Be $expected | ||
} | ||
It '-Lines count is 2 & -Level provided' { | ||
$expected = '> [!TIP]' + $newLine + '> Line 1' + $newLine + '> Line 2' + $newLine + $newLine | ||
New-MDAlert -Lines @('Line 1', 'Line 2') -Style Tip | Should -Be $expected | ||
@('Line 1', 'Line 2') | New-MDAlert -Style Tip | Should -Be $expected | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<# | ||
.SYNOPSIS | ||
This commandlet output markdown alerts based on blockquote in markdown syntax | ||
.DESCRIPTION | ||
This cmdlet outputs a quote in markdown syntax by adding `> [!STYLE]` as the first line, followed by the input lines each prefixed with `> ` on consecutive lines. | ||
.PARAMETER Lines | ||
An array of lines to quote in markdown | ||
.PARAMETER Style | ||
The Style of choice, options are one of (Tips, Warning, Note, Important, Caution), default style is Note | ||
.PARAMETER NoNewLine | ||
Controls if a new line is added at the end of the output | ||
.EXAMPLE | ||
New-MDAlert -Lines "Line 1" | ||
> [!NOTE] | ||
> Line 1 | ||
.EXAMPLE | ||
New-MDAlert -Lines @("Line 1","Line 2") -Style Important | ||
> [!IMPORTANT] | ||
> Line 1 | ||
> | ||
> Line 2 | ||
.EXAMPLE | ||
@("Line 1","Line 2") | New-MDAlert -Style Caution | ||
>> [!CAUTION] | ||
>> Line 1 | ||
>> | ||
>> Line 2 | ||
.INPUTS | ||
An array of lines | ||
.OUTPUTS | ||
First line > [!STYLE] followed by each input line with a '> ' in the front | ||
.NOTES | ||
Use the -NoNewLine parameter when you don't want the next markdown content to be separated. | ||
.LINK | ||
New-MDAlert | ||
https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts | ||
#> | ||
function New-MDAlert { | ||
[CmdletBinding()] | ||
[OutputType([string])] | ||
Param ( | ||
[Parameter( | ||
Mandatory = $true, | ||
Position = 0, | ||
ValueFromPipeline = $true | ||
)] | ||
[string[]]$Lines, | ||
[ValidateSet('Note', 'Tip', 'Important', 'Warning', 'CAUTION')] | ||
[string]$Style = 'Note', | ||
[ValidateNotNullOrEmpty()] | ||
[switch]$NoNewLine = $false | ||
) | ||
|
||
Begin { | ||
$output = '' | ||
$Admonition = '[!{0}]' -f $Style.ToUpper() | ||
$output += New-MDQuote -Lines $Admonition -Level 1 -NoNewLine | ||
} | ||
|
||
Process { | ||
$lines | ForEach-Object { | ||
$output += New-MDQuote -Lines $_ -Level 1 -NoNewLine | ||
} | ||
} | ||
|
||
End { | ||
if (-not $NoNewLine) { | ||
$output += [System.Environment]::NewLine | ||
} | ||
$output | ||
} | ||
} |