Thread: put your programs on a website

  1. #16
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    That does work, but it creates some pretty messy html. If you use a pre made javascript library, you just link to it in the <head> then all your <pre> tags automagically adds syntax highlight.

  2. #17
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Subsonics View Post
    That does work, but it creates some pretty messy html. If you use a pre made javascript library, you just link to it in the <head> then all your <pre> tags automagically adds syntax highlight.
    It's only "messy" in the sense that it uses inline style, but that's not as poor a practice as using js to mark-up static content (and I heart javascript).

    The thing to look for is something that uses css classes in the mark-up (instead of the inline style), which is tidier, and you can customize it yourself easily if you want:

    Code:
    .synStatement   {color: #00ffff}
    .synIdentifier  {color: #88ff88}
    .synConstant    {color: #ffff00}
    .synPreProc     {
            color: #ff00ff;
            font-weight:bold;
    }
    .synComment     {
            background: #cccccc; 
            color: #151515; 
            font-style:italic;
    }
    .synSpecial     {
            color: #ff4444;
            font-weight:bold;;
    }
    .synType        {color: #00aa00}
    CSS on that level is as simple as it looks.
    Full property table
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #18
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by MK27 View Post
    It's only "messy" in the sense that it uses inline style, but that's not as poor a practice as using js to mark-up static content (and I heart javascript).
    Why? To take syntaxhighlighter as an example you would put it's directory in your root folder, then:

    Code:
    <head>
    	<script type="text/javascript" src="scripts/shCore.js"></script>
    	<script type="text/javascript" src="scripts/shBrushJScript.js"></script>
    	<link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
    	<script type="text/javascript">SyntaxHighlighter.all();</script>
    </head>
    
    <body>
    
    <pre class="brush: js;">
    int main( int argc, char **argv ) 
    {
            printf("Hello World\n");
    
            return 0;
    }
    </pre>
    
    </body>

  4. #19
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    A couple of changes to the above:
    Code:
    <head>
    <script type="text/javascript" src="scripts/shCore.js"></script>
    <script type="text/javascript" src="scripts/shBrushCpp.js"></script>
    <link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
    <script type="text/javascript">SyntaxHighlighter.all();</script>
    </head>
    <body style="background: white; font-family: Helvetica">
    <pre class="brush: cpp;">
    int main(int argc, char **argv)
    {
        printf("Hello World\n");
        return 0;
    }
    </pre>
    SyntaxHighlighter seems to be what's used on this site.

  5. #20
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by oogabooga View Post
    A couple of changes to the above:
    Oops, yeah.

    And I agree, it does look similar to what is used here.

  6. #21
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Subsonics View Post
    Why?
    Because it has to be executed. I guess that is not a really big deal (people who turn js off are idiots anyway), but I'd call it "abuse" if you use it to do something that is technically not necessary.

    OTOH, looking at your example, it is pretty handy in the sense that you can easily edit the code in place, so I won't hold it against you. It would make perfect sense somewhere where the content is being generated dynamically server side (eg, here), which is presumably where it is derived from. But if you are just creating a static page -- I'd go with pregenerated mark-up. Notice that the highlighting here is very slow.

    I'll probably make use of that at some point myself, tho, lol. Text::VimColor is too slow for use in real time server side, and if you are doing dynamic content, it's always better to offload the work to the client. Thanks
    Last edited by MK27; 03-04-2012 at 10:56 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #22
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by MK27 View Post
    Because it has to be executed. I guess that is not a really big deal (people who turn js off are idiots anyway), but I'd call it "abuse" if you use it to do something that is technically not necessary.
    Yeah, I guess that's the point that could be held against it, or the person using it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 11-09-2009, 07:03 AM
  2. My Website
    By */Death*/ in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-06-2006, 04:33 AM
  3. website..
    By 1veedo in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-08-2004, 05:43 PM
  4. Programs opening programs
    By LinuxPLC in forum C Programming
    Replies: 1
    Last Post: 11-21-2002, 12:50 PM
  5. a website for simple c programs for beginners
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-06-2002, 09:38 PM