SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: code tags

  1. #1
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,996
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)

    code tags

    Hey guys, am I doing something so obviously wrong that I don't see it?

    I'm using code tags and it's just rendering like they're not there. I tried pre as well, no luck. The anchor is displaying as an anchor instead of anchor tags.

    I can has definition list, which is inside a form for convenience:
    Code:
    	  <dl>
    	    <dt>URL: </dt>
    	      <dd>http://ourwebsite.com/</dd>
    	    <dt>Site Titel: </dt>
    	      <dd>Name of Site</dd>
                <dt>Site beschrijving: </dt>
    	      <dd>blah blah blah teh Dennis</dd>
    	    <dt>HTML code:</dt>
    	      <dd><code><a href="ourwebsite.com/" title="Web Site 2.0">Web Site 2.0</a></code></dd>
    	  </dl>
    This is inside a fieldset and form and everything's checked out valid so far.

    Is there any CSS that could possibly override code's job? I have no other code tags on the site, so, no CSS for code tags.

    I haven't tested in all browsers but see it so far in FF3 and IE6 and 7. I expect the same in others.

    It must be right in front of my nose???

    Thanks,
    -poes

    *edit, justin case:
    HTML
    CSS (large page)

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The <code> tag only marks up the content as code, semantically. It doesn't change the parsing rules of HTML. You need to escape the special characters if you want to show it as actual code.

    Code:
    <code>&lt;a href="ourwebsite.com/" title="Web Site 2.0"&gt;Web Site 2.0&lt;/a&gt;</code>
    For real XHTML you could also use a CDATA section, but AFAIK only Opera supports that for HTML.
    Birnam wood is come to Dunsinane

  3. #3
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,996
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    And this isn't real XHTML, but we're always importing XML files and spitting out code and data from them so, I thought, what the hell...

    Worked, thanks! I had thought that anything inside code or pre tags were considered CDATA and therefore wouldn't need the &whatever... my colleague, until I undid it for whatever reason, used to always have submit buttons with
    value="volgende >>"
    which never threw an error.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    my colleague, until I undid it for whatever reason, used to always have submit buttons with
    value="volgende >>"
    which never threw an error.
    No, but try omitting the quotation marks …
    Birnam wood is come to Dunsinane

  5. #5
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,996
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Yeah the " were denoting CDATA I assume... that's what I thought <code> and <pre> tags could do : (

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most attribute values are of type CDATA in HTML, but the problem is that it doesn't mean the same as when an element has a content model of CDATA.

    The only HTML elements with a CDATA content model are style and script. Those are (#PCDATA) in XHTML, though.

    So CDATA attribute values != CDATA element content != CDATA section content.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tommy, is the pre tag usually wrapped around the code tag to preserve white space?

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, if you're posting a larger block of code you'd normally wrap it inside a pre element:
    Code:
    <pre><code>
      ...
    </code></pre>
    Birnam wood is come to Dunsinane

  9. #9
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,996
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Especially if you're writing Python code. It's picky on whitespace.

  10. #10
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    Especially if you're writing Python code. It's picky on whitespace.
    Django comes to mind

    5 spaces huh? I haven't played with Django in months.

  11. #11
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    15,815
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Is there some particular reason why you should use a <pre> tag rather than styling the <code> tag to retain the whitespace?

    Code:
    code {white-space:pre;}
    Last edited by felgall; Sep 24, 2008 at 19:40.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  12. #12
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Usually, when you are defining a large chunk of 'language' driven code, you do not want to manually style every line of 'code' to illusion the same whitespace that the 'pre tag' preserves.

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    15,815
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cooper.semantics View Post
    Usually, when you are defining a large chunk of 'language' driven code, you do not want to manually style every line of 'code' to illusion the same whitespace that the 'pre tag' preserves.

    That still doesn't explain why you need two tags around the content instead of just <code> and then add the line to your CSS to style it the same way a <pre> tag is styled.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE5.x browsers do not support this property. Which probably does not bother you much. IE6 supports this with a DOCTYPE but, I do not think it supports white-space: pre; if you are using a transitional DOCTYPE.

  15. #15
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Is there some particular reason why you should use a <pre> tag rather than styling the <code> tag to retain the whitespace?

    Code:
    code {white-space:pre;}
    <pre> is block-level, while <code> is inline, and for a block of code a block-level element type seems more appropriate.

    Also <pre> denotes preformatted text, i.e., text where white space has some sort of semantic meaning. This is definitely the case with languages like Python, FORTRAN and COBOL, but the semantics of white space may be more arguable in free format languages.
    Last edited by AutisticCuckoo; Sep 24, 2008 at 23:46. Reason: Typo
    Birnam wood is come to Dunsinane

  16. #16
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    15,815
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    <pre> is block-level, while <code> in inline, and for a block of code a block-level element type seems more appropriate.

    Also <pre> denotes preformatted text, i.e., text where white space has some sort of semantic meaning. This is definitely the case with languages like Python, FORTRAN and COBOL, but the semantics of white space may be more arguable in free format languages.
    Thanks Tommy, I knew there had to be a good reason for doing it that way.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

Bookmarks

Posting Permissions

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