Guide to Posting Code - Redux

Discourse uses Markdown for text formatting. There is a reference sheet and quick tutorial here: Markdown Reference

You can produce in-line code formatting by wrapping your code in backticks (`). For example, `Get-ChildItem` produces Get-ChildItem.

For larger code blocks, place a line containing three backticks above and below your code. For example

```
# 256-Color Foreground & Background Charts
echo “`n$esc[1;4m256-Color Foreground & Background Charts$esc[0m”
foreach ($fgbg in 38,48) { # foreground/background switch
foreach ($color in 0…255) { # color range
#Display the colors
$field = “$color”.PadLeft(4) # pad the chart boxes with spaces
Write-Host -NoNewLine “$esc[$fgbg;5;${color}m$field $esc[0m”
#Display 6 colors per line
if ( (($color+1)%6) -eq 4 ) { echo “`r” }
}
echo `n
}
```

produces

# 256-Color Foreground & Background Charts
echo "`n$esc[1;4m256-Color Foreground & Background Charts$esc[0m"
foreach ($fgbg in 38,48) {  # foreground/background switch
  foreach ($color in 0..255) {  # color range
    #Display the colors
    $field = "$color".PadLeft(4)  # pad the chart boxes with spaces
    Write-Host -NoNewLine "$esc[$fgbg;5;${color}m$field $esc[0m"
    #Display 6 colors per line
    if ( (($color+1)%6) -eq 4 ) { echo "`r" }
  }
  echo `n
}

The preview feature (shown on the right when typing a post) is particularly helpful for ensuring that your code displays the way you want it to. Also, note that backticks placed inside of the code block formatting are reproduced literally, rather than being interpreted as in-line code tags. If you need to show backticks in your code, I recommend using this formatting option.

Compared with our previous solution this is fairly straightforward, though it does have some limitations. For instance, there does not seem to be any way to accomplish line numbering. If anyone is aware of a good Discourse plugin for this, please share!

Update:

7 Likes
PowerShell Efficiency
Converting text file data to excel
Unlock AD with Verification
String Manipulation to CSV field
Guide to Posting Code
Trim trailing characters
CSV without quotation mark
Running Compress-Archive with Read-Host
Mu;tiple selection search in files
Deleting Files!
Image Verification - Argument Passed to Script
Strange behaviour
Need help to automate the console input
UNC path New-PSDrive script with -Credential not working
Trim trailing characters
Unlock AD with Verification
Get Exclusive value
Assistance adding ADGroupMember for multiple variables
Force Powershell to use Kerberos instead of NTLM
Grouping based on property not working
Grouping based on property not working
Function pass-through arguments
Manipulating a -size value
Trying to send notifications about expired users to Slack from Active Directory
Script to get hostsnames from Collection in specified Status
Powershell Script throwing error
Inheritance not working properly in OOP script
Problems Listing AD Group Membership
Run a powershell script with credentials
Passing variables as arguments in powershell script
DriveLetter not working
Boolean algebra
Boolean algebra
Exporting PowerShell output into .XLSX or .CSV
Array of objects questions
Fuzzy Compare dates on 2 objects
Error: Parameter set cannot be resolved using specific named parameters
IP address status with output to CSV
How to debug ERROR: HTTP request failed (listener unreachable or timed out)
Powershell script to extract report for processor queue length for last 20 days with their min, max and avg value for multiple windows servers(400 servers) and output in csv
Returning data table gives system.obect[]
SCOM Report using Powershell
Get Children From Different Time Zone
Powershell security warning popup
Get-itemproperty
Setting to Disable Timeline on Posts
Enter-PSsession fails connecting to Windows 8.1 virtual machine
AD Password Expiry Notice Script Need Help!
Help Sharepoint pnp site creation
Task Scheduler - add time to let process finish
Need Help with Automating CSV Comparison and Highlighting Differences
Script does not exit but loops
Script trying to check all Servers for user group
Visible function script block, how to create 2 separate ecommands
Dbatools diskspace report
Set-VMNetworkConfiguration: is not recognized as a name of a cmdlet
After Creating an Excel File
Adding Users and Disabling Accounts
Convert FileName from Mac with UTF8 NFC for Windows
Get a list of all domain users with attribute
Keep merging of several CSV umlauts
Log filtering to txt