googlearchive / code-prettify

An embeddable script that makes source-code snippets in HTML prettier.
Apache License 2.0
5.79k stars 906 forks source link

Powershell highlighting #295

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Powershell is extensively used for scripting on windows, it should probably 
have its own highlighting.

I've attached an incomplete but mostly functional lang-powershell.js file the 
only thing I know it has trouble with is delimited comments, which follow the 
pattern <# comment #>

Original issue reported on code.google.com by blackmag...@gmail.com on 10 Jul 2013 at 8:33

Attachments:

JohnLBevan commented 7 years ago

Regarding delimited comments, I think the below change would do the trick (NB: I've not read up on Prettify yet; just copied the pattern which Evan had used for multi-line strings).

Demo here: https://codepen.io/JohnLBevan/pen/ZyeOZO

Code below.

       [
           // Whitespace.
          [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
          // A delimited comment
          //[PR['PR_COMMENT'],     /^\x3C#[^\r\n]*#>\b/, null],
          // A line comment that starts with #
          [PR['PR_COMMENT'],     /^#[^\r\n]*/, null, '#'],
          ['opn',             /<#[^(?:#>)]+/, null, '<#'],
          ['clo',             /<#[^(?:#>)]+#>/, null, '#>'],
          // A double quoted, possibly multi-line, string.
          [PR['PR_STRING'],      /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"'],
          ['opn',             /^\(+/, null, '('],
          ['clo',             /^\)+/, null, ')'],
        ],