pre, samp, code

Discussion in 'HTML' started by Pieter Provoost, Jun 12, 2004.

  1. Hi,

    I'm trying to display some c++ code (without using >) that contains this
    line:

    #include <string>

    I tried <pre>, <samp>, <code> and <pre class="code">, but the only thing
    that works is the deprecated <xmp>. In all other case the <string> is not
    displayed. Are there any better solutions?

    Thanks!
    Pieter
    Pieter Provoost, Jun 12, 2004
    #1
    1. Advertising

  2. "Pieter Provoost" <> skrev i melding
    news:40ca3bfb$0$8415$...
    > Hi,
    >
    > I'm trying to display some c++ code (without using &gt;) that contains

    this
    > line:
    >
    > #include <string>
    >
    > I tried <pre>, <samp>, <code> and <pre class="code">, but the only thing
    > that works is the deprecated <xmp>. In all other case the <string> is not
    > displayed. Are there any better solutions?


    The < and > characters in will always (at least in IE) be used as HTML tags.
    If those tags are not valid, it won't be displayed either.

    Your solution to the problem is to convert it to the following:

    #include &lt;string&gt;

    If you're using PHP to display code samples, you can use the function
    htmlentities():
    http://www.php.net/htmlentities

    --
    Kim André Akerø
    -
    (remove NOSPAM to contact me directly)
    Kim André Akerø, Jun 12, 2004
    #2
    1. Advertising

  3. Pieter Provoost wrote:
    > I'm trying to display some c++ code (without using &gt;) that contains this
    > line:


    Why can't you use &gt; and &lt;? This is the proper way.

    > I tried <pre>, <samp>, <code> and <pre class="code">, but the only thing
    > that works is the deprecated <xmp>.


    Yes, xmp is quite old. <code> would be best.
    --
    Michael Wilcox, http://mikewilcox.t35.com/
    The all new blog! http://mikewilcox.t35.com/blog
    Michael Wilcox, Jun 12, 2004
    #3
  4. Pieter Provoost wrote:
    > I'm trying to display some c++ code (without using &gt;) that contains
    > this line:
    >
    > #include <string>


    <pre><code>#include &lt;string&gt;</code></pre>

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Jun 12, 2004
    #4
  5. Pieter Provoost

    Spartanicus Guest

    "Pieter Provoost" <> wrote:

    >I'm trying to display some c++ code (without using &gt;) that contains this
    >line:
    >
    >#include <string>


    The only proper way to do it is to replace instances of < and >, there's
    no good reason why you can't do this.

    You could also save the c++ code as a text file and embed it with an
    iframe or <object> construct, but this is a flawed method.

    --
    Spartanicus
    Spartanicus, Jun 12, 2004
    #5
  6. Pieter Provoost wrote:
    > I'm trying to display some c++ code (without using &gt;)


    Why are you trying to avoid the correct way to achive this?

    > that contains this line:
    >
    > #include <string>


    <pre><code>#include &lt;string&gt;</code></pre>

    You need to convert the reserved characters to entities.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Jun 12, 2004
    #6
  7. Spartanicus <> wrote:

    > The only proper way to do it is to replace instances of < and >,
    > there's no good reason why you can't do this.


    To be exact, the ">" character can be written as such. It's just a common
    habit to present it as &gt; for symmetry. There's no reason why a browser
    should treat ">" as anything but a data character when it is processing
    element content (as opposite to processing a tag after having encountered
    a "<" character that starts a tag).

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Jun 12, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rocky Moore
    Replies:
    7
    Views:
    1,714
    mikeb
    Jan 14, 2004
  2. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,028
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  3. Wladimir Borsov
    Replies:
    7
    Views:
    462
    Raymond Loman
    May 5, 2004
  4. Juha Nieminen
    Replies:
    3
    Views:
    1,127
    Juha Nieminen
    Feb 22, 2008
  5. Chris M. Thomasson
    Replies:
    10
    Views:
    637
    Nobody
    Aug 29, 2009
Loading...

Share This Page