none
This happens in almost every second thread when I try to edit my code :( RRS feed

Answers

  • The first thing I learned about these forums was: Edit HTML Source.

    Just using the normal editor will end up in the post having extra <p>&nbsp;</p>, <br/> and such... also, using any of the styling mid-edit will give you a brain aneurysm if you don't know exactly what you're doing.

    Second thing was: Don't try to edit code snippets.

    If you ever end up having even the tiniest of errors in a code snippet, just delete the whole block, create a new one and hope you didn't make a mistake this time. Otherwise you risk losing syntax hilight, adding extra lines, or whatever.

    I've rarely had problems since. Why the snippets ar not in a fixed width font is beyond me. (Tip: Add "pre { font-family: monospace; }" to Msdn.css)

    The editor has ALWAYS been this way. I'm just wondering where this sudden interest to it's shortcomings is coming from.

    Friday, October 7, 2011 10:45 AM
  • So edit a code block removes colorization? We'll log a bug and see if we can fix it.
    Community Forums Program Manager
    Thursday, October 6, 2011 4:24 PM
    Answerer
  • Deleting the post and re-creating the post does not seem a good solution to me - and it's too costly.

    I think you correctly identified the bug - if we post another sample using Code block it is not processed. E.g. even if I deleted the original code and created a new code block, the code is not processed! The HTML does look correct, though, but still does not work.

    I believe this bug was introduced rather recently as I don't remember having the same problem as often as now before. To me it's a big problem as I often try to correct code.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Monday, October 10, 2011 8:35 PM
    Moderator

All replies

  • I tried fixing it from IE9, but I still have the same problem. The color does not work :( I don't know why

    @ Naomi


    It looks like color only works inside pre; otherwise it gets stripped out when we submit.   I didn't even know color worked inside pre; that could be useful to know.

    So, when you edit are you losing your pre?  Trying to repair that if it is lost?

    FWIW here are some experiments I did with pre and color a while ago...

    http://social.microsoft.com/Forums/en-US/comsandbox/thread/47ec31a2-5e67-47ec-b738-d0f0d64d8f9f

    Oops.  That was a misrecollection.   Apparently color in these forums works fine.   It's Answers that strips it out.   Pre is broken though.   Also note that I was using an earlier version of WLMail to make those posts.   The latest version of WLMail makes it much harder to do that kind of thing.  I'd have to start testing again to know what is really possible now.

    I'd like to help you find a workaround.  What exactly is it that you need, do you think?


    HTH

    Robert
    ---

    Thursday, October 6, 2011 3:50 PM
  • I actually already deleted that reply (where I had the trouble) because I found a case of it not working correctly and latest reply in this thread was better solution than mine so I also updated the WiKi article with that solution instead.

    But the problem I often face now is that I post a sample of code using code block. I then try to alter this code using the code block again. At this point quite often the color is lost and nothing I try to do - deleting the whole code block and re-applying it, etc. helps. When I examine the HTML, all looks normal to me. 


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Thursday, October 6, 2011 4:09 PM
    Moderator
  • I reproduced the problem in that test thread. Here is how I do it. I post a code sample. I press Edit. I delete some white space after the code block and save again. All is well so far.

    I then select code block, press code block button again, in this case I added new comment. Make sure sql is selected. Update. Save the changes. Now the color is gone.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Thursday, October 6, 2011 4:16 PM
    Moderator
  • So edit a code block removes colorization? We'll log a bug and see if we can fix it.
    Community Forums Program Manager
    Thursday, October 6, 2011 4:24 PM
    Answerer
  • Yes, looks like this is the case - at least in many cases, but may be not 100%.
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Thursday, October 6, 2011 4:27 PM
    Moderator
  • I delete some white space after the code block and save again. All is well so far.

    I then select code block, press code block button again, in this case I added new comment. Make sure sql is selected. Update. Save the changes. Now the color is gone.

    @ Naomi

    Be careful about "delete some white space";  you could be removing some closing tags by doing that.  Watch what the Path: is showing before and after you do it, for example.   Also, doublecheck what is supposed to be happening by using the HTML button.  It doesn't mean that what you see is what you get after you hit Submit but it would improve your symptom description.

    FWIW I think it is significant that in your case the pre is being preserved but everything inside it has been stripped.   But it would be useful to know when that stripping is happening and why.

    I will see what I can do with your symptom description so far in the Sandbox thread.   ; )

     

    Robert
    ---

    Thursday, October 6, 2011 7:50 PM
  • I gave up on <pre> tags about 5 months ago. I use "Edit HTML Souce" for almost all my code, although I don't colorize anything. To me it's more important that the code be formatted correctly, so it can be read and understood. I want a fixed-width font, and I want my indenting maintained. The "Insert Code Block" feature has been modified since, but I still see problems. I understand that few (perhaps no one else) would bother, but I have a script to convert my code in a text file into the HTML I can paste.

     


    Richard Mueller - MVP Directory Services
    Friday, October 7, 2011 12:30 AM
    Moderator
  • The first thing I learned about these forums was: Edit HTML Source.

    Just using the normal editor will end up in the post having extra <p>&nbsp;</p>, <br/> and such... also, using any of the styling mid-edit will give you a brain aneurysm if you don't know exactly what you're doing.

    Second thing was: Don't try to edit code snippets.

    If you ever end up having even the tiniest of errors in a code snippet, just delete the whole block, create a new one and hope you didn't make a mistake this time. Otherwise you risk losing syntax hilight, adding extra lines, or whatever.

    I've rarely had problems since. Why the snippets ar not in a fixed width font is beyond me. (Tip: Add "pre { font-family: monospace; }" to Msdn.css)

    The editor has ALWAYS been this way. I'm just wondering where this sudden interest to it's shortcomings is coming from.

    Friday, October 7, 2011 10:45 AM
  • Second thing was: Don't try to edit code snippets.


    My Sandbox experiments show that it may be possible to have a hybrid.   And it definitely helps me to understand what is going on to change the background-color.    ; )

     

    Robert
    ---

    Friday, October 7, 2011 12:39 PM
  • I broke it again and to me this looks like a perfect HTML - what am I missing

    http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/e98321de-4c3e-4ba0-a8a1-57c07c01f65d

    <p>Try the following:</p>

    <p>&nbsp;</p>

    <pre lang="x-sql">USE tempdb 

    GO

    ALTER PROCEDURE DropTable

     

    (@TableToDrop sysname)

     

    AS

     

    IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = @TableToDrop)

       BEGIN

        DECLARE @Drop NVARCHAR(MAX)

        SET @Drop = 'DROP TABLE ' + QUOTENAME(@TableToDrop)

        EXECUTE (@Drop);

       END

    ELSE

     

        RAISERROR ('Table to drop "%s" does not exist in the current database!',16,1,@TableToDrop);

     

    GO

     

    /*To Test

     

       execute dbo.dropTable 'TableWhichNotExist'

     

    */</pre>

    <br /> <br />

    <p>&nbsp;</p>

    <br />

     

     


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Friday, October 7, 2011 7:18 PM
    Moderator
  • I pasted your code in a text file, deleted blank lines, then using Edit HTML Source I get the following when I run my script to convert into HTML:

     

    USE tempdb
    GO
    ALTER PROCEDURE DropTable

    (@TableToDrop sysname)
    AS
    IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = @TableToDrop)
        BEGIN
            DECLARE @Drop NVARCHAR(MAX)
            SET @Drop = 'DROP TABLE ' + QUOTENAME(@TableToDrop)
            EXECUTE (@Drop);
        END
    ELSE
        RAISERROR ('Table to drop "%s" does not exist in the current database!',16,1,@TableToDrop);
    GO

    /*To Test
        execute dbo.dropTable 'TableWhichNotExist'
    */

    -----

     

    I like this because if uses a fixed-width font, maintains indenting, and does not introduce extra blank lines. I see many mistakes in the forums from confusion between single and double quotes (and also back ticks used in PowerShell), lack of required spaces, extra spaces, confusing the number 1 with the letter l, etc.

    However, the HTML is ugly, and I never edit the HTML. I may make small revisions in the normal editor, but if I want to add or remove lines I start over instead. I have no colorization. I've looked at that feature and it would be difficult to implement, so I have not attempted it.

    Also, I don't see problems after I edit the reply, as I just did.

     


    Richard Mueller - MVP Directory Services
    Friday, October 7, 2011 9:01 PM
    Moderator
  • I actually like to have my posts colored. I like your font, but to me coloring is important too, because it allows me to spot error right away (say, I forgot to close a string constant with a single quote - I'll notice it in colored version right away).

    BTW, in this problematic thread I managed to break even the last message. In that last message all I did was copying the text from the 'bad' message in the clipboard, then selecting a new code block, pasting the code there and changing ALTER to CREATE.

    Yet after I saved the colorization was gone. So, it looks like if I attempt to copy the code and then even insert in a new code block on completely empty dialog, something is broken and the code comes up incorrect.

    May be a solution will be to copy the text first into another editor (say, Notepad) and then back to the Code editor.

    I don't know. But I sure want my code to be properly colored!


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Friday, October 7, 2011 9:08 PM
    Moderator
  • Ok, since I got annoyed of no colors, I went to http://www.sqlusa.com/sqlformat/, pasted my code, then grabbed it and pasted back to the thread. It produced nicer code than the Editor we have.

    So, I will try to use it more often - the code looks much nicer and I don't have a risk of loosing colors.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Friday, October 7, 2011 9:16 PM
    Moderator
  • Here is another sample.  I copied the code from a different forum and posted. I then noticed as it seems to me wrong coloring, thought I used sql instead of C#. So, I deleted the code block, created a new code block, selected C# and pasted the code. At this point the coloring was gone.

    This is HTML code - do you see anything wrong?

    <p>Found this code by Cetin Basoz in another forum, it can be used with SQL Server as well (this sample uses VFP). Just use correct connection string:</p>

    <p>&nbsp;</p>
    <pre lang="x-c#">using System;
    using System.Data;
    using System.Data.OleDb;
    class VFPDatabaseDiscovery
    {
     static void Main()
     {
       string strCon =
          @"Provider=vfpoledb;Data Source=C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 9\SAMPLES\data\testdata.dbc";
       OleDbConnection con = new OleDbConnection(strCon);
       con.Open();
       DataTable tables  = con.GetSchema("Tables");
       DataTable views   = con.GetSchema("Views");
       DataTable columns = con.GetSchema("Columns");
       con.Close();
       Console.WriteLine("Tables in catalog:");
       foreach (DataRow row in tables.Rows)
       {
          Console.WriteLine(row["table_name"]);
       }
       Console.WriteLine("Views in catalog:");
       foreach (DataRow row in views.Rows)
       {
          Console.WriteLine(row["table_name"]);
       }
       Console.WriteLine("Column info in catalog:");
       foreach (DataRow row in columns.Rows)
       {
          Console.WriteLine("{0}.{1}",row["table_name"],row["column_name"]);
       }
     }
    }
    </pre>
    <br /> <br />
    <p>&nbsp;</p>
    <span style="color: blue;">For every expert, there is an equal and opposite expert. - Becker's Law <br /> <br /> <br /> <strong><a href="http://blogs.lessthandot.com/index.php/All/?disp=authdir&amp;author=218" rel="nofollow">My blog</a></strong></span><br /><br />

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Monday, October 10, 2011 5:50 PM
    Moderator
  • This is HTML code - do you see anything wrong?

    <pre lang="x-c#">


    See my latest Sandbox experiment?   I have decided only way I can make changed code be reinterpreted is to save the current HTML, delete the post, and re-reply (starting from the saved HTML).   The symptom is that the intermediate syntax above is being kept.   So probably the post you got that from was an Edit too?  So, if your code is already colored and you need to do an edit to it, if it is a simple edit just do it in the HTML view (which shows both the normal text and the code block.)   The (main) bug is that after an Edit is Submitted the  pre  blocks are not reprocessed (if they need to be.)   Related to this if Edits of Code Blocks was actually anticipated and supported it would be nice if they would remember the Lang= parameter--especially when it is already there!   ; )

     

    Robert
    ---

    Monday, October 10, 2011 8:27 PM
  • Deleting the post and re-creating the post does not seem a good solution to me - and it's too costly.

    I think you correctly identified the bug - if we post another sample using Code block it is not processed. E.g. even if I deleted the original code and created a new code block, the code is not processed! The HTML does look correct, though, but still does not work.

    I believe this bug was introduced rather recently as I don't remember having the same problem as often as now before. To me it's a big problem as I often try to correct code.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Monday, October 10, 2011 8:35 PM
    Moderator
  • The editor has ALWAYS been this way. I'm just wondering where this sudden interest to it's shortcomings is coming from.

    I think interest to refine tools comes and goes. Always a good thing, though. =^)

    Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
    Thursday, October 13, 2011 4:57 PM
    Owner