Categories

13244

Code in Posts

I’ve been asked a couple of times recently how I put the colour highlighted code into the posts on my blog(s).

I create the posts using Live Writer. The scripts are usually developed in PowerShell ISE.  I have a script I modified from

http://www.leeholmes.com/blog/MorePowerShellSyntaxHighlighting.aspx that creates an add-on to copy the script from ISE to the clipboard.

I then chose Edit-Paste Special from the Live Writer menu and select Keep Formatting.

Only issue is ensuring that the lines of code aren’t too long for  the display width on the blog.

PowerShell pack: ISEpack

The ISEpack adds a number of commands to the Add-ons menu in ISE.  The list of additional commands includes

Add-ForeachStatement                    Add-IfStatement                         Add-InlineHelp
Add-IseMenu                             Add-Parameter                           Add-PInvoke
Add-SwitchStatement                     Close-AllOpenedFiles                    Colorize
ConvertTo-ShortcutKeyTable              Export-FormatView                       Get-CurrentFunction
Get-CurrentOpenedFileToken              Get-CurrentToken                        Get-FunctionFromFile
Get-ShellVerb                           Get-TokenFromFile                       Invoke-Line
Move-ToLastGroup                        Move-ToLastPowerShellTab                Move-ToNextGroup
Move-ToNextPowerShellTab                New-IseScript                           New-ScriptModuleFromCurrentLocation
Push-CurrentFileLocation                Push-Module                             Save-IseFileWithAutoName
Select-AllInFile                        Select-CurrentText                      Select-CurrentTextAsCommand
Select-CurrentTextAsType                Select-CurrentTextAsVariable            Show-HelpForCurrentSelection
Show-Member                             Show-SyntaxForCurrentCommand            Show-TypeConstructor
Show-TypeConstructorForCurrentType      Split-IseFile                           Switch-CommentOrText
Switch-SelectedCommentOrText

how did I generate this list

Get-ChildItem -Path (Join-Path -Path ($env:PSModulePath -split ";")[1]   -ChildPath ISEPack) -Filter *.ps1 | format-wide basename -Column 3

all built up at the command line – gotta love it when a script comes together

if you are a regular ISE user these commands could be a big help

Technorati Tags: ,