Click here to Skip to main content
Click here to Skip to main content

Formatting code in Tips and Tricks

By , 8 Apr 2013
 
Code in Tip/Trick Posts should wrapped with <pre> </pre> tags to ensure formatting and colouring are correct.

 

For example:

 

<pre lang = "vb">
' Example  
Dim test As String
</pre>
will produce:

' Example
Dim test As String
 

To specify the programming language, use lang="xxx" as follows:

 

<pre lang = "C++"> for Native C++ Formatting
<pre lang = "mc++"> for C++/CLI Formatting
<pre lang = "aspnet"> for ASP.NET Formatting
<pre lang = "cs"> forC# Formatting
<pre lang = "css"> for CSS Formatting
<pre lang = "F#"> for F# Formatting
<pre lang = "html"> for HTML Formatting
<pre lang = "Java"> for Java Formatting
<pre lang = "jscript"> for JavaScript Formatting
<pre lang = "asm"> for MASM/ASM Formatting
<pre lang = "msil"> for MSIL Formatting
<pre lang = "midl"> for MIDL Formatting
<pre lang = "php"> for PHP Formatting
<pre lang = "sql"> for SQL Formatting
<pre lang = "vbscript"> for VBScript Formatting
<pre lang = "xml"> for XML Formatting
If you want to enter text like <pre lang = "xml">,

  1. Check the allow HTML radio button in the Tip/Trick editor "When Pasting" option list. Use the article editor to enter text. Copy its HTML and paste here.

  2. Learn the special text for symbols like <(&-lt-; Remove the - for the symbol)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Anshul R
Student
India India
Member
No Biography provided

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralReason for my vote of 5 Good onememberEswa11 Dec '10 - 4:05 
Reason for my vote of 5
Good one
GeneralTwo things: this information is already included in the arti...memberknockNrod14 Sep '10 - 6:18 
Two things: this information is already included in the article FAQ, and you may want to add lang="vb.net".
GeneralOne problem...memberSteve Wellens4 Sep '10 - 13:33 
I enter code like this:
 
<pre>
      <script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
      <script src="Scripts/jquery-ui-1.8.4.custom.min.js" type="text/javascript"></script>
      <link type="text/css" href="css/smoothness/jquery-ui-1.8.4.custom.css" rel="stylesheet" />
</pre>
 
...and it looks OK.   Hover, if I go back and make a minor change...not even touching the code, it looks like this:
 
<pre>
      &lt;</span />script</span /> src</span />=&quot;</span />Scripts/jquery-1.4.2.min.js&quot;</span /> type</span />=&quot;</span />text/javascript&quot;</span />&gt;</span />&lt;/</span />script</span />&gt;</span />
      &lt;</span />script</span /> src</span />=&quot;</span />Scripts/jquery-ui-1.8.4.custom.min.js&quot;</span /> type</span />=&quot;</span />text/javascript&quot;</span />&gt;</span />&lt;/</span />script</span />&gt;</span />
      &lt;</span />link</span /> type</span />=&quot;</span />text/css&quot;</span /> href</span />=&quot;</span />css/smoothness/jquery-ui-1.8.4.custom.css&quot;</span /> rel</span />=&quot;</span />stylesheet&quot;</span /> /</span />&gt;</span />
</pre>
 
If I save it, the code seems to get double-processed and the whole post gets messed up.
 
How can I stop the editor from destroying the text?   I've tried using the lang tags but it makes no difference.
 

Thanks.
 
Steve Wellens
GeneralRe: One problem...memberSteve Wellens28 Nov '10 - 3:47 
Here is more editor mangling. Switching to raw HTML and pasting this simple block in should work. But it doesn't.
 
<pre lang="html">
<%-- Span is to allow child page to jQuery select textbox--%>
<span id="SpanMyTextBox">
<asp:TextBox ID="MyTextBox" runat="server"></asp:TextBox>
</span>
</pre>
Steve Wellens

GeneralRe: One problem...memberpranav9529 Nov '10 - 0:26 
As far as I know, there isn't any way out of this because the " symbol is more editor friendly than "
SuggestionRe: One problem...memberShahan Ayyub24 Mar '13 - 5:03 
I faced the same issue and since then i took a backup of edited text in MSWord before moving forward (and paste it when come back and formatting get lost). It saved me to make the same changes again.
 
See if it helps!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 9 Apr 2013
Article Copyright 2010 by Anshul R
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid