What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

This question already has an answer here:

Some times, when pasting a chunk of code I want to highlight where the fault is or where I want to highlight attention.

For a real example, my question could be about why the MSDN doesn't use a full address/path when referring to the testfile.txt

EG

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
    public class WebRequestGetExample
    {
        public static void Main ()
        {
            // Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
            request.Method = WebRequestMethods.Ftp.UploadFile;

            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

            // Copy the contents of the file to the request stream.
            StreamReader sourceStream = new StreamReader("testfile.txt");
            byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

            response.Close();
            }
        }
    }
}

I think it would be great if I could highlight the code like I have in this poorly-cropped image:

enter image description here

So much easier for me to highlight where I want people to look (especially if for example, the string "testfile.txt" occurred multiple times), and often the additional code is useful so those helping asking the question can see the entire method!

What do we think?

share|improve this question

marked as duplicate by dmckee, hims056, Bo Persson, animuson, Rory Feb 11 '13 at 21:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
meta.stackexchange.com/questions/32705/bold-code-in-a-question (which is [status-declined]) and many others "linked" to it. –  dmckee Feb 11 '13 at 17:31
    
I actually wanted it highlighted, not bold but I guess it's similar. May be my question wasn't clear; when I create a post, I have user friendly buttons which let me make things bold/italic/add picture etc. I'd want a highlight button option in there! Further since the 'dupe' was first posted in 2009 I can only assume it needs to be revisited since the answers on the other post (and let's be honest, they're work arounds and not answers) do not solve it. Or, does this mean the 'elves' at SO just may not think it's popular/important enough to implement at this stage? –  Dave Feb 12 '13 at 10:08

1 Answer 1

Best you can achieve is being able to use bold or italics, when using <code> tag:

// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("testfile.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

However this way you'll lose code prettify which renders only code blocks marked with four spaces.

In cases where you need to highlight parts of the posted code, mention it in the post itself and you can link to external place holding the code in a nicer format if you have such a place.

share|improve this answer
    
Yeah, I had got similar but the colouring is so helpful (IMO) that I wouldn't want to sacrifice it. Thank you for the suggestion. Your edit, about copying pasting the relevant code, could just add noise to the page, where as a quick highlight keeps the post (hopefully) shorter! –  Dave Feb 11 '13 at 13:48
2  
You can put it in a code block and have a comment pointing at that line with something like // PROBLEM HERE !!! –  ben is uǝq backwards Feb 11 '13 at 14:01

Not the answer you're looking for? Browse other questions tagged .