Connecting Tech Pros Worldwide Forums | Help | Site Map

How to make html ignore code that is part of text?

deko
Guest
 
Posts: n/a
#1: Jul 23 '05
I need to include code snippets in my html document, something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" "Password=password;Persist Security
Info=True;User ID=newuser;Initial Catalog=catalog;Data Source=localhost" />
</appSettings>
</configuration>

If I try to put this in a regular document, I get errors... I've tried
enclosing it in <pre> tags, but that didn't help. How do I get this code
sample into a document?

Thanks



Leif K-Brooks
Guest
 
Posts: n/a
#2: Jul 23 '05

re: How to make html ignore code that is part of text?


deko wrote:[color=blue]
> I need to include code snippets in my html document, something like this:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <appSettings>
> <add key="ConnectionString" "Password=password;Persist Security
> Info=True;User ID=newuser;Initial Catalog=catalog;Data Source=localhost" />
> </appSettings>
> </configuration>
>
> If I try to put this in a regular document, I get errors... I've tried
> enclosing it in <pre> tags, but that didn't help. How do I get this code
> sample into a document?[/color]

Change the less-than signs ("<") to "&lt;", the ampersands ("&") to
"&amp;", and the greater-than signs (">") to "&gt;".
Mark Tranchant
Guest
 
Posts: n/a
#3: Jul 23 '05

re: How to make html ignore code that is part of text?


deko wrote:
[color=blue]
> I need to include code snippets in my html document[/color]

You need to use &lt; and &gt; instead of < and >.

See http://tranchant.plus.com/web/html-tutorial/characters

--
Mark.
http://tranchant.plus.com/
deko
Guest
 
Posts: n/a
#4: Jul 23 '05

re: How to make html ignore code that is part of text?


> Change the less-than signs ("<") to "&lt;", the ampersands ("&") to[color=blue]
> "&amp;", and the greater-than signs (">") to "&gt;".[/color]

Thanks!!


deko
Guest
 
Posts: n/a
#5: Jul 23 '05

re: How to make html ignore code that is part of text?


> See http://tranchant.plus.com/web/html-tutorial/characters

very helpful link... thanks!


Spartanicus
Guest
 
Posts: n/a
#6: Jul 23 '05

re: How to make html ignore code that is part of text?


"deko" <www-dot-clearpointsystems-dot-com@nospam.com> wrote:
[color=blue]
>I need to include code snippets in my html document, something like this:
>
><?xml version="1.0" encoding="utf-8" ?>
><configuration>
> <appSettings>
> <add key="ConnectionString" "Password=password;Persist Security
>Info=True;User ID=newuser;Initial Catalog=catalog;Data Source=localhost" />
> </appSettings>
></configuration>
>
>If I try to put this in a regular document, I get errors... I've tried
>enclosing it in <pre> tags, but that didn't help. How do I get this code
>sample into a document?[/color]

Replace occurrences of < with &lt; , for consistency you might also
consider replacing > with &gt;

Then enclose it in:

<pre><code>
....
</code></pre>

markup.

--
Spartanicus
deko
Guest
 
Posts: n/a
#7: Jul 23 '05

re: How to make html ignore code that is part of text?


> Replace occurrences of < with &lt; , for consistency you might also[color=blue]
> consider replacing > with &gt;
>
> Then enclose it in:
>
> <pre><code>
> ...
> </code></pre>
>
> markup.[/color]

That did the trick:

<pre>
<code>
&lt?xml version="1.0" encoding="utf-8" ?&gt;
&ltconfiguration&gt
&ltappSettings&gt
&ltadd key="ConnectionString" "Password=password;Persist Security
Info=True;User ID=newuser;Initial Catalog=database;Data Source=localhost"
/&gt
&lt/appSettings&gt
&lt/configuration&gt
</code>
</pre>

looks great... thanks


Jukka K. Korpela
Guest
 
Posts: n/a
#8: Jul 23 '05

re: How to make html ignore code that is part of text?


"deko" <www-dot-clearpointsystems-dot-com@nospam.com> wrote:
[color=blue][color=green]
>> Replace occurrences of < with &lt; , for consistency you might also
>> consider replacing > with &gt;
>>
>> Then enclose it in:
>>
>> <pre><code>
>> ...
>> </code></pre>
>>
>> markup.[/color]
>
> That did the trick:[/color]

Consider that an illusion.
[color=blue]
> <pre>
> <code>
> &lt?xml version="1.0" encoding="utf-8" ?&gt;
> &ltconfiguration&gt
> &ltappSettings&gt
> &ltadd key="ConnectionString" "Password=password;Persist Security
> Info=True;User ID=newuser;Initial Catalog=database;Data
> Source=localhost" /&gt
> &lt/appSettings&gt
> &lt/configuration&gt
> </code>
> </pre>[/color]

You are not using the semicolon as instructed. Terminating entity
references with semicolon has always been good practice in HTML, and in
XHTML it is obligatory - an XHTML conformant browser is _required_ to
choke on your usage. Besides, e.g. &ltadd is invalid in good old HTML
too, and is to be treated as an undefined entity reference.

As a minor detail, it is a bit safer to write

<pre><code>&lt;?xml version="1.0" ...
...
&lt;/configuration&gt;</code></pre>

i.e. to have no line breaks after <pre> and <code> tags or before </code>
or </pre> tags. The reason is that many browsers get the relevant parsing
rules wrong and may understand the situation so that there is an empty
line at the start of the <pre> element and at the end of it. You might
see this if you set a background color or a border for the <pre> element.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Lars Eighner
Guest
 
Posts: n/a
#9: Jul 23 '05

re: How to make html ignore code that is part of text?


In our last episode,
<dAd%c.16689$bh7.2444@newssvr29.news.prodigy.com >,
the lovely and talented deko
broadcast on comp.infosystems.www.authoring.html:
[color=blue]
> I need to include code snippets in my html document, something like this:[/color]
[color=blue]
><?xml version="1.0" encoding="utf-8" ?>
><configuration>
> <appSettings>
> <add key="ConnectionString" "Password=password;Persist Security
> Info=True;User ID=newuser;Initial Catalog=catalog;Data Source=localhost" />
> </appSettings>
></configuration>[/color]
[color=blue]
> If I try to put this in a regular document, I get errors... I've tried
> enclosing it in <pre> tags, but that didn't help. How do I get this code
> sample into a document?[/color]

Change < to &lt; and > to &gt;




--
Lars Eighner -finger for geek code- eighner@io.com http://www.io.com/~eighner/
If it wasn't for muscle spasms, I wouldn't get any exercise at all.
Lāʻie Techie
Guest
 
Posts: n/a
#10: Jul 23 '05

re: How to make html ignore code that is part of text?


On Tue, 07 Sep 2004 07:38:49 +0000, deko wrote:
[color=blue]
> I need to include code snippets in my html document, something like this:
>
> <?xml version="1.0" encoding="utf-8" ?> <configuration>
> <appSettings>
> <add key="ConnectionString" "Password=password;Persist Security
> Info=True;User ID=newuser;Initial Catalog=catalog;Data Source=localhost"
> />
> </appSettings>
> </configuration>
>
> If I try to put this in a regular document, I get errors...[/color]

What kind of errors? when? Do you mean it no longer validates as strict
HTML 4 or XHTML?
[color=blue]
> I've tried enclosing it in <pre> tags, but that didn't help. How do I
> get this code sample into a document?[/color]

To display code snippets, encode the angle brackets and singe and double
quotes. Formatting can be improved by wrapping it with "<pre><code>"
(<pre> to preserve white space, <code> to use a monospace font).

HTH,
La'ie Techie

Mark Parnell
Guest
 
Posts: n/a
#11: Jul 23 '05

re: How to make html ignore code that is part of text?


On Wed, 08 Sep 2004 01:10:24 -0600, Lāʻie Techie
<laie@win_remove_get_nospam_solutions.com> declared in
comp.infosystems.www.authoring.html:
[color=blue]
> (<pre> to preserve white space, <code> to use a monospace font).[/color]

That depends on the browser, the CSS and the user's settings (not
necessarily in that order).

pre { font-family: monospace; }
code { font-family: serif; }

--
Mark Parnell
http://www.clarkecomputers.com.au
Spartanicus
Guest
 
Posts: n/a
#12: Jul 23 '05

re: How to make html ignore code that is part of text?


L??ie Techie <laie@win_remove_get_nospam_solutions.com> wrote:
[color=blue]
><code> to use a monospace font).[/color]

Use <code> to markup code, not for presentational purposes.

--
Spartanicus
Jan Roland Eriksson
Guest
 
Posts: n/a
#13: Jul 23 '05

re: How to make html ignore code that is part of text?


On Tue, 07 Sep 2004 09:15:18 +0100, Spartanicus <me@privacy.net> wrote:
[color=blue]
>"deko" <www-dot-clearpointsystems-dot-com@nospam.com> wrote:
>[color=green]
>>I need to include code snippets in my html document...[/color][/color]

[...]
[color=blue]
>Replace occurrences of < with &lt; , for consistency you might also
>consider replacing > with &gt;[/color]
[color=blue]
>Then enclose it in:
>
><pre><code>
>...
></code></pre>[/color]

It seems more correct to me to use the following markup

<code>
<pre>...</pre>
</code>

where the '...' sequence represents the exact preformatted code element
content, with entity references included where required.

After all the OP asked for how to include a CODE section in a way that
it would be rendered as an example of markup.

The 'CODE' element has a semantic definition attached to it and should
thus be at the major level of markup in relation to 'PRE'.

A 'PRE' element has no specific semantics attached to it, and it is in
my eyes only presentational. It should as such only be involved at the
end of any branch in a parse tree.

--
Rex


Steve Pugh
Guest
 
Posts: n/a
#14: Jul 23 '05

re: How to make html ignore code that is part of text?


Jan Roland Eriksson <jrexon@newsguy.com> wrote:[color=blue]
>On Tue, 07 Sep 2004 09:15:18 +0100, Spartanicus <me@privacy.net> wrote:[color=green]
>>"deko" <www-dot-clearpointsystems-dot-com@nospam.com> wrote:
>>[color=darkred]
>>>I need to include code snippets in my html document...[/color]
>>
>><pre><code>
>>...
>></code></pre>[/color]
>
>It seems more correct to me to use the following markup
>
> <code>
> <pre>...</pre>
> </code>[/color]

Shame it isn't valid. :-/
[color=blue]
>The 'CODE' element has a semantic definition attached to it and should
>thus be at the major level of markup in relation to 'PRE'.[/color]

Unfortunately code is an inline element ...
[color=blue]
>A 'PRE' element has no specific semantics attached to it, and it is in
>my eyes only presentational. It should as such only be involved at the
>end of any branch in a parse tree.[/color]

.... and pre is a block element.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <steve@pugh.net> <http://steve.pugh.net/>
Neal
Guest
 
Posts: n/a
#15: Jul 23 '05

re: How to make html ignore code that is part of text?


On Wed, 08 Sep 2004 01:10:24 -0600, Lāʻie Techie
<laie@win_remove_get_nospam_solutions.com> wrote:
[color=blue]
> To display code snippets, encode the angle brackets and singe and double
> quotes. Formatting can be improved by wrapping it with "<pre><code>"
> (<pre> to preserve white space, <code> to use a monospace font).[/color]

pre = block level element which preserves white space. Many browsers'
default rendering is monospace.

code = inline element which semantically defines an example of code. Many
browsers' default rendering is monospace.

Neither should be chosen to force a monospace font. CSS (selector
{font-family: monospace;}) should be used for that purpose.
Neal
Guest
 
Posts: n/a
#16: Jul 23 '05

re: How to make html ignore code that is part of text?


On Wed, 08 Sep 2004 16:29:01 -0400, Neal <neal413@yahoo.com> wrote:
[color=blue]
> Neither (pre or code) should be chosen to force a monospace font. CSS
> (selector {font-family: monospace;}) should be used for that purpose.[/color]

And of course, user CSS or a no-CSS UA can make that suggestion moot...
Spartanicus
Guest
 
Posts: n/a
#17: Jul 23 '05

re: How to make html ignore code that is part of text?


Neal <neal413@yahoo.com> wrote:
[color=blue]
>force[/color]

Who's a naughty boy then? ;-)

--
Spartanicus
Jan Roland Eriksson
Guest
 
Posts: n/a
#18: Jul 23 '05

re: How to make html ignore code that is part of text?


On Wed, 08 Sep 2004 21:22:15 +0100, Steve Pugh <steve@pugh.net> wrote:
[color=blue]
>Jan Roland Eriksson <jrexon@newsguy.com> wrote:[/color]
[...][color=blue][color=green]
>>It seems more correct to me to use the following markup
>> <code>
>> <pre>...</pre>
>> </code>[/color]
>
>Shame it isn't valid. :-/[/color]

Yes I know that, sadly I stopped writing before I had indicated whatever
implications that was attached to my line of thought.

I still stand for my line of thinking as described though. PRE is
presentational and should in reality have been defined as an "inline
element.

--
Rex


Neal
Guest
 
Posts: n/a
#19: Jul 23 '05

re: How to make html ignore code that is part of text?


On Thu, 09 Sep 2004 00:37:53 +0100, Spartanicus <me@privacy.net> wrote:
[color=blue]
> Neal <neal413@yahoo.com> wrote:
>[color=green]
>> force[/color]
>
> Who's a naughty boy then? ;-)
>[/color]


Sorry, it just happened! I promise I won't do it again!

(No, my girlfriend didn't buy it either...)
Closed Thread