Answered by:
New forum failures.

Question
-
Forums now fail to colorize code added. All code is in black and white.
See this thread:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/d22dba05-27e0-4256-8d7c-e176e8a8b3c3
Latest entries are not colorized.
Forum continues to reformat and lose characters when post is saved.
Trying to bold and selection always results in loss of characters on first try. Crl-Z and do again will work.
¯\_(ツ)_/¯
Answers
-
- Marked as answer by jrv Monday, September 24, 2012 7:53 PM
All replies
-
-
Here is the failing HTML that was injected when PowerSHell formatting was selected:
<pre class="prettyprint"><# import Autocorrect List into Word 2010.ps1 Defaults to current PowerShell folder and default filename. You can create a file using this: $word.AutoCorrect.Entries| select name,value,RichText| export-csv autocorrect.csv -notype #> [CmdLetBinding()] Param( $file='autocorrect.csv', $path=$pwd ) $filepath="$path\$file" $filepath if(-not (Test-Path $filepath) ){ Write-Host 'File not found' -ForegroundColor red return } # file contains twio columns - name and value both are stings. $csv = Import-Csv -Path $filepath Write-Host 'Auto.csv File found. Processing...' -ForegroundColor green $word = New-Object -ComObject word.application Foreach($entry in $word.AutoCorrect.entries){ Try{ if($entry.RichText){ $word.AutoCorrect.Entries.AddRichText($entry.Name, $entry.Value) }else{ $word.AutoCorrect.Entries.Add($entry.Name, $entry.Value) } } Catch{ Write-Error ('Failed to add:' + $entry.Name) } } Write-Host 'Autocorrect list entries added' -ForegroundColor green $word.Quit() $word = $null [gc]::collect() [gc]::WaitForPendingFinalizers()</pre>
Note that even this is not colorized correctly.
It also has a <pre - "prettyprint" that seems ambiguous.
¯\_(ツ)_/¯
- Edited by jrv Wednesday, September 12, 2012 7:21 PM
-
I think the HTML is the same as it has been for awhile now, using class prettyprint. Other PowerShell code seems to be colorized as before (when I test in the TechNet Sandbox). I think your example fooled the code completely.
Richard Mueller - MVP Directory Services
The issue is that the OP posted colorized code from another tool. This appears to have broken the style renderings. This indicates that the style sheets used to colorize the code are not designed correctly as they should be removing all inheritance before they are applied to the "prettyprint" <pre>
This happens fairly often along with other things that make it hard to use the code blocks successfully.
If yu go to the link I posted you will see that all code posted after a point except for the OPs colorized code is without color. You can use the code block and post some code it it will happen again.
This fails on both IE8 and IE9. I have not tested on IE10 or chrome etc.
¯\_(ツ)_/¯
-
Here is the difference.
When the style breaks we get one <pre setting and when it is good we gat another/
Here is a good Pre tag:
<pre class="prettyprint" style="">Option Explicit
Notice the style=""
The broken style is missing that. Whenever that is mising the style is not applied correctly or at all.
I suspect this is a problem with variations in the distribution servers.
¯\_(ツ)_/¯
-
UPDATE: I submitted a bug request.
Thanks!
Ed Price (a.k.a User Ed), SQL Server Experience Program Manager (Blog, Twitter, Wiki)
It seems to only happen when someone pastes colorized code from an external tool.
I posted a link to the thread that does it everytime but the link seems to have disappeared.
Here is the link again. All of my posts have no colorizations. I suspect you can also create a post and paste some POwerSHell code into the code box and see if it still does that. I have two posts there that both failed.
Here is a new test post here:
<# import Autocorrect List into Word 2010.ps1 Defaults to current PowerShell folder and default filename. You can create a file using this: $word.AutoCorrect.Entries| select name,value,RichText| export-csv autocorrect.csv -notype #> [CmdLetBinding()] Param( $file='autocorrect.csv', $path=$pwd ) $filepath="$path\$file" $filepath if(-not (Test-Path $filepath) ){ Write-Host 'File not found' -ForegroundColor red return } # file contains twio columns - name and value both are stings. $csv = Import-Csv -Path $filepath Write-Host 'Auto.csv File found. Processing...' -ForegroundColor green $word = New-Object -ComObject word.application Foreach($entry in $word.AutoCorrect.entries){ Try{ if($entry.RichText){ $word.AutoCorrect.Entries.AddRichText($entry.Name, $entry.Value) }else{ $word.AutoCorrect.Entries.Add($entry.Name, $entry.Value) } } Catch{ Write-Error ('Failed to add:' + $entry.Name) } } Write-Host 'Autocorrect list entries added' -ForegroundColor green $word.Quit() $word = $null [gc]::collect() [gc]::WaitForPendingFinalizers()
Hah - I see it:
This should work:
[CmdLetBinding()] Param( $file='autocorrect.csv', $path=$pwd ) $filepath="$path\$file" $filepath if(-not (Test-Path $filepath) ){ Write-Host 'File not found' -ForegroundColor red return } # file contains twio columns - name and value both are stings. $csv = Import-Csv -Path $filepath Write-Host 'Auto.csv File found. Processing...' -ForegroundColor green $word = New-Object -ComObject word.application Foreach($entry in $word.AutoCorrect.entries){ Try{ if($entry.RichText){ $word.AutoCorrect.Entries.AddRichText($entry.Name, $entry.Value) }else{ $word.AutoCorrect.Entries.Add($entry.Name, $entry.Value) } } Catch{ Write-Error ('Failed to add:' + $entry.Name) } } Write-Host 'Autocorrect list entries added' -ForegroundColor green $word.Quit() $word = $null [gc]::collect() [gc]::WaitForPendingFinalizers()
The problem is
<#
#>
They are not parsed in the colorizer and once inserted at5 the beginning of script the whole block fails to colorize.
Proof:
# # # <# import Autocorrect List into Word 2010.ps1 Defaults to current PowerShell folder and default filename. You can create a file using this: $word.AutoCorrect.Entries| select name,value,RichText| export-csv autocorrect.csv -notype #> [CmdLetBinding()] Param( $file='autocorrect.csv', $path=$pwd ) $filepath="$path\$file" $filepath if(-not (Test-Path $filepath) ){ Write-Host 'File not found' -ForegroundColor red return } # file contains twio columns - name and value both are stings. $csv = Import-Csv -Path $filepath Write-Host 'Auto.csv File found. Processing...' -ForegroundColor green $word = New-Object -ComObject word.application Foreach($entry in $word.AutoCorrect.entries){ Try{ if($entry.RichText){ $word.AutoCorrect.Entries.AddRichText($entry.Name, $entry.Value) }else{ $word.AutoCorrect.Entries.Add($entry.Name, $entry.Value) } } Catch{ Write-Error ('Failed to add:' + $entry.Name) } } Write-Host 'Autocorrect list entries added' -ForegroundColor green $word.Quit() $word = $null [gc]::collect() [gc]::WaitForPendingFinalizers()
By adding a couple of # before the <# we get it past the colorizer bugs.
This is part of all of the edit issues with posisiton and insertion including the bold conten deleteion issues. Thisis due to bad pointer arithmatic. Remember that mesages in Windows are not guaranteed to be delivered in the same order that they were sent. If we send a message that adjust a number another message can undo that adjustment. In a browser we have no way to control this. That is also why I and others keep getting jscript errors with "pointer out of bounds" messages which I have posted about here many times.
So start any code block with <# and it will likely fail to colorize correctly.
¯\_(ツ)_/¯
- Edited by jrv Thursday, September 13, 2012 1:54 AM
-
I just confirmed in the TechNet sandbox. PowerShell code (using Insert Code Block) that begins with a multi-line comment (anything between the <# and #> delimiters) has no colorization at all.
Richard Mueller - MVP Directory Services
Thanks Richard. I am pretty sure that always adding one extra comment to the beginning will prevent that. The code block script is looking at the first character as it it is the begining of tag. If that character is not the first character the issue doesn't happen.
. <# import Autocorrect List into Word 2010.ps1 Defaults to current PowerShell folder and default filename. You can create a file using this: $word.AutoCorrect.Entries| select name,value,RichText| export-csv autocorrect.csv -notype #> [CmdLetBinding()] Param( $file='autocorrect.csv', $path=$pwd ) $filepath="$path\$file" $filepath if(-not (Test-Path $filepath) ){ Write-Host 'File not found' -ForegroundColor red return }
This time I added a dot first and it bypasses teh bug. A space won't work. Only a printable character works so the erro happens ater eth HTML conversion pass which is what strips out all of teh foramtting and removes blank lines. That needs to be fixed too.
¯\_(ツ)_/¯
-
Test with Insert Code Block:
Source Code from here: http://msdn.microsoft.com/en-us/library/ebca9ah3.aspx1 Just hit the COPY javascript upper right to copy code and choose the Language C# when use Code Block.
abstract class ShapesClass { abstract public int Area(); } class Square : ShapesClass { int side = 0; public Square(int n) { side = n; } // Area method is required to avoid // a compile-time error. public override int Area() { return side * side; } static void Main() { Square sq = new Square(12); Console.WriteLine("Area of the square = {0}", sq.Area()); } interface I { void M(); } abstract class C : I { public abstract void M(); } } // Output: Area of the square = 144
2 Use Ctrl + C to copy Code then insert with Code Block:
abstract class ShapesClass { abstract public int Area(); } class Square : ShapesClass { int side = 0; public Square(int n) { side = n; } // Area method is required to avoid // a compile-time error. public override int Area() { return side * side; } static void Main() { Square sq = new Square(12); Console.WriteLine("Area of the square = {0}", sq.Area()); } interface I { void M(); } abstract class C : I { public abstract void M(); } } // Output: Area of the square = 144
Pan Zhang Customer Support EPX Service Engineering Support Team
Then Ed or Irv, can you point out if my repro steps are aligning with yours? Seem it doesn't disappoint me.- Edited by Pan Zhang Thursday, September 13, 2012 2:35 AM Confirm the result with OPs
-
-
Hi Richard and Irv,
So the problem only happens when you choose the PowerShell in Code Block, other languages don't act as the scenario above?
Can you confirm? Thanks
Pan Zhang Customer Support EPX Service Engineering Support Team
<# abstract class ShapesClass { abstract public int Area(); } class Square : ShapesClass { int side = 0; public Square(int n) { side = n; } // Area method is required to avoid // a compile-time error. public override int Area() { return side * side; } static void Main() { Square sq = new Square(12); Console.WriteLine("Area of the square = {0}", sq.Area()); } interface I { void M(); } abstract class C : I { public abstract void M(); } }
It will happen with any language as you can see above.
The good this is that few langauges use that constuct so C# would sue /* instead of <#.
The issue is that teh counters are including a leading < into teh HTML when it belongs inside the <pre> tags.
At least 50% of the issues with the forum editors are the bad counters. A failure to fix those may make any other fixes incalid or more difficult. Fixiong them after other issues have been addressed may well undo the other fixes. It is hard to tell but this is the kind of bug that should be fixed first.
¯\_(ツ)_/¯
-
-
- Marked as answer by jrv Monday, September 24, 2012 7:53 PM
-