8000 Merge 6173e4de3eb94771d1bdaa27da49bb34db36e270 into dbb9bd469b9bd5e87… · Sarafian/MarkdownPS@c9e8edc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c9e8edc

Browse files
authored
Merge 6173e4d into dbb9bd4
2 parents dbb9bd4 + 6173e4d commit c9e8edc

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

Demo/Demo.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ $lines=@(
9191
$markdown+=New-MDQuote -Lines $lines
9292
#endregion
9393

94+
#region Github Flavoured Markdown Alerts
95+
$markdown+=New-MDHeader "Github Flavoured Markdown Alerts"
96+
$markdown+=New-MDParagraph -Lines "This is an important information"
97+
$lines=@(
98+
"Alert is special callout style used in Github Flavoured Markdows"
99+
)
100+
$markdown+=New-MDAlert -Lines $lines -Style Important
101+
102+
$markdown+=New-MDParagraph -Lines "Multi line Alert with 'Tip' Style"
103+
$lines=@(
104+
"Git is "
105+
"Line 2"
106+
)
107+
$markdown+=New-MDAlert -Lines $lines -Style Tip
108+
#endregion
109+
94110
#region
95111
$markdown+=New-MDHeader "Links"
96112
$markdown+="This is "+(New-MDLink -Text "an example" -Link "http://www.example.com/")+" inline link."

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A powershell module to render markdown files.
2323
- New-MDList
2424
- New-MDParagraph
2525
- New-MDQuote
26+
- New-MDAlert
2627
- New-MDTable
2728

2829
# Example script
@@ -123,6 +124,22 @@ $lines=@(
123124
$markdown+=New-MDQuote -Lines $lines
124125
#endregion
125126
127+
#region Github Flavoured Markdown Alerts
128+
$markdown+=New-MDHeader "Github Flavoured Markdown Alerts"
129+
$markdown+=New-MDParagraph -Lines "This is an important information"
130+
$lines=@(
131+
"Alert is special callout style used in Github Flavoured Markdows"
132+
)
133+
$markdown+=New-MDAlert -Lines $lines -Style Important
134+
135+
$markdown+=New-MDParagraph -Lines "Multi line Alert with 'Tip' Style"
136+
$lines=@(
137+
"Git is "
138+
"Line 2"
139+
)
140+
$markdown+=New-MDAlert -Lines $lines -Style Tip
141+
#endregion
142+
126143
#region
127144
$markdown+=New-MDHeader "Links"
128145
$markdown+="This is "+(New-MDLink -Text "an example" -Link "http://www.example.com/")+" inline link."
@@ -234,6 +251,18 @@ $markdown
234251
>
235252
> > Line 1
236253
> > Line 2
254+
>
255+
> # Github Flavoured Markdown Alerts
256+
> This is an important information
257+
>
258+
> > [!IMPORTANT]
259+
> > Alert is special callout style used in Github Flavoured Markdows
260+
>
261+
> Multi line Alert with 'Tip' Style
262+
>
263+
> > [!TIP]
264+
> > Git is
265+
> > Line 2
237266
>
238267
> # Links
239268
> This is [an example](http://www.example.com/) inline link.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
BeforeAll {
2+
. $PSCommandPath.Replace('.Tests.ps1', '.ps1')
3+
$MDQuoteFile = Join-Path -Path (Split-Path $PSCommandPath -Parent) -ChildPath 'New-MDQuote.ps1'
4+
. $MDQuoteFile
5+
$newLine = [System.Environment]::NewLine
6+
}
7+
Describe -Tag @('MarkdownPS', 'Cmdlet', 'Public') 'New-MDAlert' {
8+
It '-Lines is null' {
9+
{ New-MDAlert -Lines $null } | Should -Throw '*because it is null.*'
10+
}
11+
It '-Lines is empty' {
12+
{ New-MDAlert -Lines @() } | Should -Throw '*because it is an empty array.*'
13+
}
14+
It '-Style out of range' {
15+
{ New-MDAlert -Lines 'Line 1' -Style Unknown } | Should -Throw -ErrorId 'ParameterArgumentValidationError,New-MDAlert'
16+
}
17+
}
18+
Describe -Tag @('MarkdownPS', 'Cmdlet', 'Public', 'New-MDAlert') 'New-MDAlert' {
19+
It '-Lines count is 1 & -Style not specified' {
20+
$expected = '> [!NOTE]' + $newLine + '> Line 1' + $newLine + $newLine
21+
New-MDAlert -Lines 'Line 1' | Should -Be $expected
22+
New-MDAlert -Lines @('Line 1') | Should -Be $expected
23+
'Line 1' | New-MDAlert | Should -Be $expected
24+
@('Line 1') | New-MDAlert | Should -Be $expected
25+
}
26+
It '-Lines count is 2 & -Style not specified' {
27+
$expected = '> [!NOTE]' + $newLine + '> Line 1' + $newLine + '> Line 2' + $newLine + $newLine
28+
# New-MDAlert -Lines @('Line 1', 'Line 2') | Should -Be $expected
29+
@('Line 1', 'Line 2') | New-MDAlert | Should -Be $expected
30+
}
31+
It '-Lines count is 1 & -Style provided' {
32+
$expected = '> [!TIP]' + $newLine + '> Line 1' + $newLine + $newLine
33+
New-MDAlert -Lines 'Line 1' -Style Tip | Should -Be $expected
34+
New-MDAlert -Lines @('Line 1') -Style Tip | Should -Be $expected
35+
'Line 1' | New-MDAlert -Style Tip | Should -Be $expected
36+
@('Line 1') | New-MDAlert -Style Tip | Should -Be $expected
37+
}
38+
It '-Lines count is 2 & -Level provided' {
39+
$expected = '> [!TIP]' + $newLine + '> Line 1' + $newLine + '> Line 2' + $newLine + $newLine
40+
New-MDAlert -Lines @('Line 1', 'Line 2') -Style Tip | Should -Be $expected
41+
@('Line 1', 'Line 2') | New-MDAlert -Style Tip | Should -Be $expected
42+
}
43+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<#
2+
.SYNOPSIS
3+
This commandlet output Github Flavoured Markdown alerts based on blockquote in markdown syntax
4+
5+
.DESCRIPTION
6+
This cmdlet outputs a quote in markdown syntax which are Github Flavoured Markdown syntax, by adding `> [!STYLE]` as the first line, followed by the input lines each prefixed with `> ` on consecutive lines.
7+
Refer "https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts" for more details.
8+
9+
.PARAMETER Lines
10+
An array of lines to quote in markdown
11+
12+
.PARAMETER Style
13+
The Style of choice, options are one of (Tips, Warning, Note, Important, Caution), default style is Note
14+
15+
.PARAMETER NoNewLine
16+
Controls if a new line is added at the end of the output
17+
18+
.EXAMPLE
19+
New-MDAlert -Lines "Line 1"
20+
21+
> [!NOTE]
22+
> Line 1
23+
24+
.EXAMPLE
25+
New-MDAlert -Lines "Line 1" -Style Tip
26+
27+
> [!NOTE]
28+
> Line 1
29+
30+
# Style accepts one of 4 value (Note, Tip, Important and Warning)
31+
32+
.EXAMPLE
33+
New-MDAlert -Lines @("Line 1","Line 2") -Style Important
34+
35+
> [!IMPORTANT]
36+
> Line 1
37+
> Line 2
38+
39+
.EXAMPLE
40+
@("Line 1","Line 2") | New-MDAlert -Style Caution
41+
42+
>> [!CAUTION]
43+
>> Line 1
44+
>> Line 2
45+
46+
.LINK
47+
Refer "https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts" for more details.
48+
49+
.INPUTS
50+
An array of lines and choice of Style
51+
52+
.OUTPUTS
53+
First line > [!STYLE] followed by each input line with a '> ' in the front
54+
55+
.NOTES
56+
Use the -NoNewLine parameter when you don't want the next markdown content to be separated.
57+
58+
.LINK
59+
New-MDAlert
60+
https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
61+
#>
62+
function New-MDAlert {
63+
[CmdletBinding()]
64+
[OutputType([string])]
65+
Param (
66+
[Parameter(
67+
Mandatory = $true,
68+
Position = 0,
69+
ValueFromPipeline = $true
70+
)]
71+
[string[]]$Lines,
72+
[ValidateSet('Note', 'Tip', 'Important', 'Warning', 'CAUTION')]
73+
[string]$Style = 'Note',
74+
[ValidateNotNullOrEmpty()]
75+
[switch]$NoNewLine = $false
76+
)
77+
78+
Begin {
79+
$output = ''
80+
$admonition = '[!{0}]' -f $Style.ToUpper()
81+
$output += New-MDQuote -Lines $admonition -Level 1 -NoNewLine
82+
}
83+
84+
Process {
85+
$lines | ForEach-Object {
86+
$output += New-MDQuote -Lines $_ -Level 1 -NoNewLine
87+
}
88+
}
89+
90+
End {
91+
if (-not $NoNewLine) {
92+
$output += [System.Environment]::NewLine
93+
}
94+
$output
95+
}
96+
}

0 commit comments

Comments
 (0)
0