Issue #914 resolved

Rendering issue in PowerShell Code

Anonymous created an issue

Here's a piece of a (private) PowerShell script we're hosting on GitHub, where I noticed the rendering issue.

if( $Html ) {
    Write-Host -NoNewline "> Determining embedded content...";
    $cidRegex = [regex]"cid:([^`"]+)";
    $Matches = $cidRegex.Matches( $body );
    Write-Host "Done. Found" $Matches.Count "elements";
    Write-Host ">";

    if( $Matches.Count -gt 0 ) {
        $alternateView = [System.Net.Mail.AlternateView]::CreateAlternateViewFromString( $body, $null, "text/html" );

        foreach( $contentId in $Matches ) {
            $id = $contentId.Groups[1].Value;
            if( Test-Path $id ) {
                $filePath =  $(get-location).Path + "\" + $id;

                Write-Host ">    - ``"$id"`` **found** (will be used in email)  ";
                Write-Host ">      → ``$filePath``";

                $contentElement = New-Object System.Net.Mail.LinkedResource( $filePath );
                $contentElement.ContentId = $id;

                $alternateView.LinkedResources.Add( $contentElement );

            } else {
                Write-Host ">    - ``"$id"`` missing";
            }
        }   
    }
}
Write-Host "";

It seems like the double backticks are causing some kind of confusion. In case it isn't apparent, the highlighting confuses which parts are string which aren't towards the end of the script.

Comments (8)

  1. Joon Ro

    It seesm the brackets are causing the problem. One of my complied Sphinx doc does not highlight the following line:

    [System.IO.File]::WriteAllLines($ORGFILE, $Content)
    
  2. Georg Brandl repo owner

    The problem is the unquoted double-quote at "$id" which Pygments sees as terminating the string. I don't know the exact rules of PowerShell strings: is that allowed?

    Also, does the double backtick have any special meaning?

  3. Anonymous

    That double backtick is resolved to a single backtick. A single backtick would indicate line continuation. The script outputs Markdown, so the final backtick then indicates fixed-width formatting.

    Also, it's not really "$id". The $id is actually contained within 2 strings that are enclosed in "".

  4. Log in to comment