11

I would like to be able to pull some code samples out of a database and/or have the text embedded into the website and then have the sample formatted in a code like fashion on the screen. While the text alone on the screen is great, the format will make it more user friendly. How is this done?

I want this:

 public string MyString = "The Sample Text";


To look like:

public string MyString = "The Sample Text";


EDIT WITH ANSWER
I took Gortok's suggestion and looked into Prettify.js and its doing just what I had hoped. Here is how this is implemented.

<head runat="server">
    <script src="Scripts/prettify.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <link href="Scripts/prettify.css" rel="stylesheet" type="text/css"></link>
</head>
<body>
    <code class="prettyprint"> 
        public String HelloString = "New String"; 
    </code>  
    <script language="javascript"> 
        $().ready(function() { 
            prettyPrint(); 
        }); 
    </script> 
</body> 

3 Answers 3

25

Stack Overflow uses prettify.js from Google.

Sign up to request clarification or add additional context in comments.

Comments

7

I use SyntaxHighlighter by Alex Gorbatchev

http://alexgorbatchev.com/wiki/SyntaxHighlighter

It's used on Yahoo Developer Network

http://developer.yahoo.com/yui/animation/

Comments

4

would this help:

http://code.google.com/p/syntaxhighlighter/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.