Public/ConvertTo-MarkdownHeader.ps1
Function ConvertTo-MarkdownHeader { <# .SYNOPSIS Converts strings to Markdown headings. .DESCRIPTION Converts strings to Markdown headings by inserting the correct number of hashes based on the -Level parameter at the beginning of the string value. .PARAMETER String The text to convert. .PARAMETER Level The sub-heading level to apply. The higher the number, the smaller the heading. .EXAMPLE "Hello World!" | ConvertTo-MarkDownHeader .EXAMPLE ConvertTo-MarkDownHeader "Hello World!" -Level 5 .EXAMPLE ConvertTo-MarkDownHeader -String "Hello World!" -Level 2 .EXAMPLE "Hello","World!" | ConvertTo-MarkDownHeader #> [CmdletBinding()] PARAM ( [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] [ValidateNotNullOrEmpty()] [String[]]$String, [Parameter(Mandatory=$false, Position=1, ValueFromPipeline=$false)] [ValidateRange(1,5)] [Int]$Level = 1 ) #region BEGIN Block BEGIN { # Locally scope ErrorActionPreference for predictable behavior of Try/Catch blocks inside the function $ErrorActionPreference = 'Stop' # Create output variable $Results = [System.Collections.ArrayList]::new() } #endregion BEGIN Block #region PROCESS Block PROCESS { FOREACH ($Entry in $String) { # Insert Markdown syntax into $Entry based on $Level $Entry = ($Entry).Insert(0, $("#"*$Level+" ")) # Add to results $Results.Add($Entry) | Out-Null } } #endregion PROCESS Block #region END Block END { Return $Results } #endregion END Block } |