Skip to content

Commit

Permalink
Handle common line continuation in PS
Browse files Browse the repository at this point in the history
This fixes error with line continuation character in the middle of the
string interpolation.
  • Loading branch information
tancnle committed Dec 12, 2022
1 parent 94696df commit f285a44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rouge/lexers/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class Powershell < RegexLexer

rule %r/[-+*\/%=!.&|]/, Operator
rule %r/[{}(),:;]/, Punctuation

rule %r/`$/, Str::Escape # line continuation
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/visual/samples/powershell
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,10 @@ function NewVMSnapshot {
[string[]]$Description = "`Snapshot taken via $(Split-Path $PSCommandPath -leaf) by $global:vsphereuser."
)
}

# Handle line continuation in string interpolation
Get-CimInstance -ComputerName localhost win32_logicaldisk `
| where caption -eq "C:" `
| foreach-object {write " $($_.caption) $('{0:N2}' `
-f ($_.Size/1gb)) GB total, $('{0:N2}' `
-f ($_.FreeSpace/1gb)) GB free "}

0 comments on commit f285a44

Please sign in to comment.