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

This question already has an answer here:

If I'm trying to post a question/answer on Stack Overflow, with some code that contains HTML text syntax inside, how do I do it nice with highlights. For example, I would like to post this line:

QString html = QString("<html><head><meta Content=\"Text/html; CHARSET=Windows-1251\"></head><body>%1</body></html>").arg(text);

But output is shown as QString html = QString("%1").arg(text);.

I have read this post what-html-tags-are-allowed-on-stack-overflow, but I didn't find the answer.

share|improve this question

marked as duplicate by animuson, Lucifer, ben is uǝq backwards, Mat, Martijn Pieters Jun 21 '13 at 12:54

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.

4 Answers 4

up vote 4 down vote accepted

Select the text you want to highlight and click the 101 010 button:

int main() { return; }

alt text


QString html = QString("<html><head><meta Content=\"Text/html; CHARSET=Windows-1251\"></head><body>%1</body></html>").arg(text);
share|improve this answer
    
@Kop: thanks for reply, but that does not work with QString html = QString("<html><head><meta Content=\"Text/html; CHARSET=Windows-1251\"></head><body>%1</body></html>").arg(text); example. –  mosg Apr 28 '10 at 11:22
    
@mosg: as you see from my edit it does work. Just select it and press the 101010 button. –  Andreas Bonini Apr 28 '10 at 11:33
    
@mosg sure it does. What are you talking about? –  Pëkka Apr 28 '10 at 11:33
    
@Kop & Pekka: I do posting as you sad, press "101 010" button on selected code line, and after that in preview section text looked like it cut all html syntax from the code line. Is this normal and it's all that I have is to press Post Question button? –  mosg Apr 28 '10 at 11:40
    
+1 An unconventional (not red) freehand circle, but it definitely highlights the 101 010 button and gives meaning to the text. –  tvanfosson Apr 28 '10 at 11:50
    
Ok, here is the full code example, which I'm trying to post with syntax highlights (as you can see, I have already post it, but with big troubles) - stackoverflow.com/questions/2727080/… There I have to use "101 010" with "Blockquote" button to gain such a representation of page witch is now... –  mosg Apr 28 '10 at 12:16
3  
@mosg - looks like there is a bug with the markdown preview (at least) when the code sample follows a list. Putting some text (or as you did a blockquote) between the two solves the issue with respect to the preview. I didn't check if the issue carried over to the live display. Since the mark up is produced server side for that it could certainly be ok even when the preview (which is implemented in javascript) isn't. –  tvanfosson Apr 28 '10 at 12:25
    
@tvanfosson: I saw, that you correct my post, - thanks, so how did you do that? –  mosg Apr 28 '10 at 13:07
    
@mosg - I have enough rep to be able to edit other's posts. –  tvanfosson Apr 28 '10 at 19:13
    
@tvanfosson: Thanks for all replies. Just for now, I tested posting Qt & HTML code together, so it's looks good! :) –  mosg Apr 29 '10 at 7:21

Also, if you need your "code" to be inline -- as @Kop has done in naming the button -- you can use back ticks (``) to signify that the surrounded text is code. As in "what about the <html> tag?"

EDIT: Based on your comment, it appears to be a bug in the markdown preview when the code sample follows a list. All that is needed is some plain text between the list and the code sample.

share|improve this answer

Besides formatting as code you can also URL encode "<" as "&lt;":

QString html = QString("&lt;html>&lt;head>&lt;meta Content=\"Text/html; CHARSET=Windows-1251\">&lt;/head>&lt;body>%1&lt;/body>&lt;/html>").arg(text);

It will display as: QString html = QString("<html><head><meta Content=\"Text/html; CHARSET=Windows-1251\"></head><body>%1</body></html>").arg(text);

share|improve this answer
    
@Peter Mortensen: just for now, I can't vote, but after gaining 15 reputations, I will vote for your reply! :) Thanks, you solution is one of best, but what if I need to post a few lines of such code? Do I have to replace all > symbols to &lt;? –  mosg Apr 28 '10 at 12:21
    
@mosg: yes, replace all instances of "<" (it is not required for ">"). It is only required for HTML tags. –  Peter Mortensen Apr 28 '10 at 13:30
    
Hm, but some how, tvanfosson do the trick: in original post ( stackoverflow.com/questions/2727080/… ) he correct my post, without replacing "<" symbols... How did he do it - the secret for me... –  mosg Apr 28 '10 at 14:05

Indent code by 4 spaces

QString html = QString("<html><head><meta Content=\"Text/html; CHARSET=Windows-1251\"></head><body>%1</body></html>").arg(text);

See http://meta.stackoverflow.com/editing-help

share|improve this answer
    
@Jeff Atwood: thank. I have read it before posting my question, but it seams that only I faced with this problem... strange... –  mosg Apr 28 '10 at 11:36
1  
@Jeff -- there appears to be a bug in the markdown preview when the code sample directly follows a list. See the link in the comments on @Kop's answer for the example. If you remove the "Sample Code" text (my edit), the preview doesn't show the code properly -- or at least didn't for me on my Mac using Safari. –  tvanfosson Apr 28 '10 at 12:27
    
@tvan this old chestnut? meta.stackexchange.com/questions/19624/… –  Jeff Atwood Apr 28 '10 at 12:38

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