Testing A New Syntax Highlighter

This is a test of a new syntax highlighting plugin that works for WordPress-hosted blogs.  I think I’m going to like it!  I’ll post here the same code as in my previous post.  In that one I couldn’t get it formatted acceptably by my previous favorite, Code Snippet so I had to try something else that I didn’t like but at least was readable.  This one seems to work much better, probably because it was specifically designed to work with WordPress.


$ErrorActionPreference = "stop"
Set-StrictMode -Version "latest"

$testroot = $env:temp + "\PSTipsTest"

# set up a test directory with subdirectories and files, for use later on.
try
{
    if (Test-Path $testroot)
    {
        Remove-Item $testroot -Recurse
    }

    New-Item -ItemType directory -Path $testroot -Force | Out-Null

    New-Item -ItemType file -Path "$testroot\testfile.txt" -Value "test file" -force | Out-Null

    $subdirA = "$testroot\subdir1"
    New-Item -ItemType directory -Path $subdirA -Force | Out-Null
    New-Item -ItemType file -Path "$subdirA\anothertestfile.txt" -Value "test file" -force | Out-Null

    $subdirB = "$testroot\subsub2"
    New-Item -ItemType directory -Path $subdirB -Force | Out-Null
    New-Item -ItemType file -Path "$subdirB\yetanothertestfile.txt" -Value "test file" -force | Out-Null
}
catch
{
    throw "Error setting up test: $_"
}

# show the directory structure we just created
cls
#dir $testroot -Recurse
#"`r`n`r`n"

# this is the equivalent of the code from the Powershell tip.
# Its recommendation was to not use Set-StrictMode -Version "latest" because you'd get an error.
# I disagree--it's buggy code and catching it with Set-StrictMode is a good thing.
try
{
    Dir $testroot  | 
        Where-Object { $_.Length -lt 1MB } | 
        select name

}
catch
{
    "The dir command failed due to a bug.  $_"    # you'll see this error occur.
}


"`r`n`r`n"

# I think this code is better.  You can use Set-StrictMode, and its intent is also clearer.
try
{
    Dir $testroot  | 
        Where-Object {!$_.PSIsContainer} | 
        Where-Object { $_.Length -lt 1MB } | 
        select name
}
catch
{
    "this error should not happen: $_"    # you won't see this error occur.
}

"here is a really long line.  I don't want these to wrap--they're strings!  What we should get instead is a horizontal scrollbar for the posted code.  That keeps this code intact and runnable, even if lines like this should not be written because they're too hard to read."

If this works out well for me I’ll leave this post up; otherwise I’ll probably edit it to let you know why I am not going to use the plugin.

I do like it.  But I have noticed a couple issues:

  • No matter the setting for “wraplines”, those long string lines at the bottom get wrapped and I don’t get a scrollbar.
  • The toolbar you get if you hover over the posted code doesn’t include the “copy to clipboard” icon that I think it’s supposed to.

Update:  well, now the wraplines feature is working.  I edited that long string and all of a sudden it’s fine.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: