HighDots Forums  

<pre> with js

alt.html alt.html


Discuss <pre> with js in the alt.html forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jan C. Faerber
 
Posts: n/a

Default <pre> with js - 10-25-2009 , 10:49 AM






I read that in XML you can use CDATA sections to show code in a
browser.
When you use HTML you can use the <pre> tag.
It works fine. I think <code> makes just the font style.

But when I use <script language="[...] in the <pre> section
and when I don't change <table> into &lt;table&gt; and so on
(well, I forgot at the moment what exactly prevents the browser
to use the code as usual) the <pre> tag becomes useless.

http://www.lovedieu.eu/javascript/resize.html
Here I tried to present some code including
<script etc. > and { ... } sections.
It was not working.

Is there a stronger tag than the <pre> tag to present code?

Reply With Quote
  #2  
Old   
Jan C. Faerber
 
Posts: n/a

Default Re: <pre> with js - 10-25-2009 , 10:52 AM






On Oct 25, 3:49*pm, "Jan C. Faerber" <faerber.... (AT) gmail (DOT) com> wrote:
Quote:
Is there a stronger tag than the <pre> tag to present code?
Asked more precisely:
How can I show the whole html source code of
http://www.lovedieu.eu/javascript/resizeview.html
on
http://www.lovedieu.eu/javascript/resize.html

thx

Reply With Quote
  #3  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: <pre> with js - 10-25-2009 , 01:01 PM



Jan C. Faerber wrote:

Quote:
I read that in XML you can use CDATA sections to show code in a
browser.
You misread, more or less. CDATA sections are for inserting character data
(C = character) to be treated as such, even if it contains constructs that
would normally be taken as tags or entity or character references in XML. It
has nothing particular to do with "code", whatever that means, though of
course computer code often contains "<" or "&".

XML as such is virtually useless on the Web.

Quote:
When you use HTML you can use the <pre> tag.
That's preformatted text. It does not have anything particular to do with
"code" or with CDATA. It just means that whitespace is preserved.

Quote:
It works fine.
For some values of "work" and "fine", yes.

Quote:
I think <code> makes just the font style.
The <code> markup indicates that the content is computer code. It does not
override normal HTML or XML rules for "<" or "&" in any way. On graphic
browsers, the content is typically rendered in a monospace font by default,
but that's coincidental.

Quote:
But when I use <script language="[...] in the <pre> section
and when I don't change <table> into &lt;table> and so on
(well, I forgot at the moment what exactly prevents the browser
to use the code as usual) the <pre> tag becomes useless.
The description is confused but sufficient for indicating that you expected
<pre> to have a meaning different from its defined meaning. It is indeed
useless or worse then.

Quote:
Is there a stronger tag than the <pre> tag to present code?
The robust approach is to "escape" the characters "&" and "<" as required by
HTML rules. It's easy, and if you need to do it often, you can surely create
a macro or a program for the purpose, if you are qualified enough to give
advice to others in matters of programming.

But since you asked, there's a "stronger" tag, still supported by browsers,
<xmp>, though it has been deprecated since its origin, through millennia.,
and isn't even part of any comtemporary HTML specification.
--
Yucca, http://www.cs.tut.fi/~jkorpela/

Reply With Quote
  #4  
Old   
Jan C. Faerber
 
Posts: n/a

Default Re: <pre> with js - 10-25-2009 , 06:33 PM



On Oct 25, 6:01*pm, "Jukka K. Korpela" <jkorp... (AT) cs (DOT) tut.fi> wrote:

Quote:
The robust approach is to "escape" the characters "&" and "<" as requiredby
HTML rules. It's easy, and if you need to do it often, you can surely create
a macro or a program for the purpose, if you are qualified enough to give
advice to others in matters of programming.
After some copy&fix&paste I got a form which can do it to get a nice
result:
http://www.lovedieu.eu/alt.html/fred.html and I updated my link
http://www.lovedieu.eu/alt.html/resize2.html

Thank you for your hints - only I still don't understand the problem
with "&".
Is it better to change them to "&amp;"?

Reply With Quote
  #5  
Old   
dorayme
 
Posts: n/a

Default Re: <pre> with js - 10-26-2009 , 03:31 AM



In article <dw%Em.31992$La7.24883 (AT) uutiset (DOT) elisa.fi>,
"Jukka K. Korpela" <jkorpela (AT) cs (DOT) tut.fi> wrote:

Quote:
Is there a stronger tag than the <pre> tag to present code?

The robust approach is to "escape" the characters "&" and "<" as required by
HTML rules. It's easy, and if you need to do it often, you can surely create
a macro
Somewhere along the line, to get "<" and ">", I got or made:

Replace

<([^<>]+)>

with

\&lt;\1\&gt;

in my patterns in BBEdit.

--
dorayme

Reply With Quote
  #6  
Old   
Jan C. Faerber
 
Posts: n/a

Default Re: <pre> with js - 10-26-2009 , 06:13 AM



On Oct 25, 6:01*pm, "Jukka K. Korpela" <jkorp... (AT) cs (DOT) tut.fi> wrote:

Quote:
But when I use <script language="[...] * in the <pre> section
and when I don't change <table> into &lt;table> and so on
(well, I forgot at the moment what exactly prevents the browser
to use the code as usual) the <pre> tag becomes useless.

The description is confused but sufficient for indicating that you expected
pre> to have a meaning different from its defined meaning. It is indeed
useless or worse then.

hm... I think they aimed to achieve that with some good reason.
I found that the innerHTML e.g. of a <div> will also not allow to past
the html declaration or javascript syntax completly. But this is js
topic.
Same with ajax.
Just wanted to add that the exact point of time might be relevant when
some code is used by a browser.
So maybe a script should work within a <pre> section?
But that is really js topic. Sorry. Or?
At least it gets truncated for the presentation.
I did not continue any further studies in that direction.
Securityreasons? Seperate Programming from Mark-Up? etc...

Reply With Quote
  #7  
Old   
Adrienne Boswell
 
Posts: n/a

Default Re: <pre> with js - 10-26-2009 , 09:35 AM



Gazing into my crystal ball I observed "Jan C. Faerber"
<faerber.jan (AT) gmail (DOT) com> writing in news:036a70bd-b837-43cd-8316-
90a3f8a93709 (AT) g23g2000vbr (DOT) googlegroups.com:

Quote:
only I still don't understand the problem
with "&".
Is it better to change them to "&amp;"?

Yes, always escape ampersand.

In my authoring, I always use the whole word "and" unless the ampersand is
a part of a company's name, like Ben & Jerry's.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Reply With Quote
  #8  
Old   
Andy Dingley
 
Posts: n/a

Default Re: <pre> with js - 10-26-2009 , 10:51 AM



On 25 Oct, 17:01, "Jukka K. Korpela" <jkorp... (AT) cs (DOT) tut.fi> wrote:

Quote:
XML as such is virtually useless on the Web.
If we accept "The Web" as "that part of the internet that's
addressable by URLs", then XML is widely used and useful within it.
The web is accessed by user agents, not all of which are either
interactive, nor "web browsers". Many of these user agents do indeed
make good use of XML.

Reply With Quote
  #9  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: <pre> with js - 10-26-2009 , 12:09 PM



Andy Dingley wrote:

Quote:
On 25 Oct, 17:01, "Jukka K. Korpela" <jkorp... (AT) cs (DOT) tut.fi> wrote:

XML as such is virtually useless on the Web.

If we accept "The Web" as "that part of the internet that's
addressable by URLs", then XML is widely used and useful within it.
Indeed, but not as such. It is used as a data format behind the scenes, not
as delivery format to be directly displayed by browsers.

Of course I could and should have formulated my statement more carefully.
The point is that XML is not a replacement for HTML.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Reply With Quote
  #10  
Old   
Jan C. Faerber
 
Posts: n/a

Default Re: <pre> with js - 10-26-2009 , 01:07 PM



On Oct 26, 2:35*pm, Adrienne Boswell <arb... (AT) yahoo (DOT) com> wrote:

Quote:
only I still don't understand the problem
with "&".
Is it better to change them to "&"?
Hey - hey - hey!
Don't spoil my quoted ampersand!! I wrote "&amp;"!

Quote:
Yes, always escape ampersand. *
I wonder if you never get a mess with a recursive problem
like ( ( ( &amp; ) amp; ) amp; ) amp;

Quote:
In my authoring, I always use the whole word "and" unless the ampersand is
a part of a company's name, like Ben & Jerry's.
which authoring?

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.