Skip to content

Set-MarkdownCodeBlock

SYNOPSIS

Generates a fenced code block for Markdown using the specified language.

SYNTAX

Set-MarkdownCodeBlock [-Language] <String> [-Content] <ScriptBlock> [-Execute]
 [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

This function takes a programming language and a script block, and depending on the provided parameters, either captures the script block's literal text (with indentation normalized) or executes it and captures the string representation of the output. It then formats the result as a fenced code block suitable for Markdown.

EXAMPLES

EXAMPLE 1

Set-MarkdownCodeBlock -Language 'powershell' -Content {
    Get-Process
}

Output:

Get-Process

Generates a fenced code block with the specified PowerShell script.

EXAMPLE 2

CodeBlock 'powershell' {
    Get-Process
}

Output:

Get-Process

Generates a fenced code block with the specified PowerShell script.

EXAMPLE 3

CodeBlock -Language 'powershell' -Content {
    Get-Process | Select-Object -First 1
} -Execute

Output:

NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
------    -----      -----     ------      --  -- -----------
    13     4.09      15.91       0.00    9904   0 AggregatorHost

Generates a fenced code block with the output of the specified PowerShell script.

PARAMETERS

-Language

{{ Fill Language Description }}

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Content

{{ Fill Content Description }}

Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Execute

{{ Fill Execute Description }}

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

string

NOTES

Returns the formatted fenced code block as a string.

https://psmodule.io/Markdown/Functions/Set-MarkdownCodeBlock/