Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post

    How to show source code on page?

    On a webpage, how can you show code (HTML, CSS, Javascript) so that it isn't used as part of that page itself? I mean, say I want to show the following code on the page:

    <h1>Sample Code</h1>

    How can I get the actual code to appear, and not have it integrate into the page?

  • #2
    Senior Coder
    Join Date
    Jul 2002
    Posts
    1,628
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <pre></pre> - preformatted plain text
    or you could put it in a <textarea></textarea>

    Moderator: General web building

    Get out from under them, resist and multiply.
    Get out from under precipice and see the sky.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    simply use html entities instead of the characters.

    for instance, &lt; instead of < and & copy; for the copyright symbol

    look here:

    http://www.ramsch.org/martin/uni/fmi-hp/iso8859-1.html

    Some programs like Dreamweaver will automatically convert special characters to entities, otherwise you will have to do it yourself.

    ::] krycek [::

    EDIT: I had to put a space in & copy; so that it wouldn't actually display &copy; lol
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Surround it in a CDATA section:

    <![CDATA[

    my markup

    ]]>

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    The PRE tag didn't seen to work. Here's the code I used:

    <pre>
    <html>
    <head>
    <title>Sample</title>
    </head>
    <body>
    <h1>Hello World!</h1>
    </body>
    </html>
    </pre>

    All I saw was the heading. No code.

    I will give the newer suggestions a try.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    Wouldn't using the HTML entities be more time consuming, having to put all those little codes in for simple symbols?

    The CDATA thing didn't work. Again, all I saw was the heading. I did the following:

    <![CDATA[
    <pre>
    <html>
    <head>
    <title>Sample</title>
    </head>
    <body>
    <h1>Hello World!</h1>
    </body>
    </html>
    </pre>
    ]]>

    So far, only the textarea solution has worked for me. Are there any other possibilities, or have I been doing something wrong with my other attempts?

  • #7
    New Coder
    Join Date
    Oct 2002
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try using an html program like dreamweaver or frontpage if you want to use the entities, and go much faster. I think that is the easiest way to do it.

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    &lt;html&gt;<br />
    &lt;head&gt;<br />
    &lt;title&gt;Sample&lt;/title&gt;<br />
    &lt;/head&gt;<br />
    &lt;body&gt;<br />
    &lt;h1&gt;Hello World!&lt;/h1&gt;<br />
    &lt;/body&gt;<br />
    &lt;/html&gt;
    ...that's the ONLY way to do it if you want it actually on your page, i.e. not in a textarea.

    using <pre> will not help, the only thing pre does is to display it as preformatted text - you may want that as well, however to display the actal chars you need to use their entities.

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #9
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    It doesn't work for me, jkd.

    I couldn't even open the page in Internet Explorer 6!

    I did open it in Dreamwevaer, however, and it worked in the preview inside Dreamweaver.

  • #11
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    jkd, I tested this, it is true it does not work in IE.

    Also, as far as I know, Grant did not say he was using xhtml.

    Grant, you are gonna have to use entities, sorry!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #12
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I believe there is an <xmp> tag in HTML that lets you do this...

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    So....Character entities or a textbox?

  • #14
    Senior Coder
    Join Date
    Jul 2002
    Posts
    1,628
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yea try <xmp></xmp>
    i had forgotten about that one
    it worked for me when i needed it before.

    Moderator: General web building

    Get out from under them, resist and multiply.
    Get out from under precipice and see the sky.

  • #15
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    Great, that works! What is XMP anyway? Example? Is it supported in HTML/XHTML?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •