[REBOL]HTML tags in content, not in source
[1/11] from: tim:johnsons-web at: 29-Oct-2000 8:58
Howdy:
I need to be able to display literal representations of HTML
tags in the content itself.
example:
test: func[][print "<!--TEST-->"]
calling test results in the comment tag being placed in the
source code.
I want it to appear in the content itself.
Any ideas.
TIA
Tim
[2/11] from: joel:neely:fedex at: 29-Oct-2000 13:12
Hi, Tim,
Is this what you meant, or did I misunderstand the question?
>> some-html: [
[ <html> newline
[ <head> newline
[ <title> {Hello, world!} </title> newline
[ </head> newline
[ <body bgcolor="#000066" text="#ffffcc"> newline
[ <h3> {Hello, world!} </h3> newline
[ <h4> {(Especially Tim!)} </h4> newline
[ <p> {Is this what you meant?} </p> newline
[ </body> newline
[ </html> newline
[ ]
== [
<html> newline
<head> newline
<title> "Hello, world!" </title> newline
</head> newline
<body bgcolor="...
>> print some-html
<html>
<head>
<title> Hello, world! </title>
</head>
<body bgcolor="#000066" text="#ffffcc">
<h3> Hello, world! </h3>
<h4> (Especially Tim!) </h4>
<p> Is this what you meant? </p>
</body>
</html>
>> write %some-page.html
...etc...
[rebol-bounce--rebol--com] wrote:
[3/11] from: al:bri:xtra at: 30-Oct-2000 9:19
Tim Johnson wrote:
> Howdy:
> I need to be able to display literal representations of HTML tags in the content itself.
<<quoted lines omitted: 3>>
> I want it to appear in the content itself.
> Any ideas.
Could you explain what you are trying to do? What is 'test in?
Andrew Martin
The one and only Rebol Server Pages expert :-)
[4/11] from: tim:johnsons-web at: 29-Oct-2000 14:35
Hi Al and Joe:
I've just got a minute here. If I'm still not clear enough,
I'll have to write a simple test script and send it tomorrow.
I want to be able to show an actual tag in the web
content that my CGI program writes, to give directions
to a user.
maybe I just have to rely on '< and '>
I'm sure that will work.
Thanks a bunch folks!
Later
Tim
[Al--Bri--xtra--co--nz] wrote:
[5/11] from: al:bri:xtra at: 30-Oct-2000 11:58
Tim Johnson wrote:
> I want to be able to show an actual tag in the web content that my CGI program writes,
to give directions to a user. Maybe I just have to rely on '< and '> I'm sure that
will work.
Yes, that's what you have to do. Take a look at my R2HTML.r script of Rebol.org for an
example of what has to be done. I've got a much nicer version of R2HTML.r on my home
computer which I must post to Rebol.org...
Andrew Martin
Writing better Rebol scripts all the time...
[6/11] from: joel:neely:fedex at: 29-Oct-2000 20:12
[rebol-bounce--rebol--com] wrote:
> Hi Al and Joe:
> I've just got a minute here. If I'm still not clear enough,
<<quoted lines omitted: 4>>
> maybe I just have to rely on '< and '>
> I'm sure that will work.
Ah! Now I understand. Yes, the bottom-level solution is the HTML
entities that are "escapes" for < and >. However, you can REBOLize
the process, as illustrated in the following:
html-escape: func [s [string!] /local r] [
r: copy s
replace/all r #"&" #"^@" ; hide ampersands
replace/all r #"<" "<" ; escape lt
replace/all r #">" ">" ; escape gt
replace/all r #"^"" """ ; escape double-quotes
replace/all r #"^@" "&" ; un-hide ampersands
insert head r <pre>
insert tail r </pre>
r
]
>> para: {
{ <p>This is a paragraph
{ <!-- Hello, world! -->
{ with an HTML comment
{ in the middle</p>
{ }
== {
<p>This is a paragraph
<!-- Hello, world! -->
with an HTML comment
in the middle</p>
}
>> print [
[ <html> newline
[ <head> <title> {Sample} </title> </head> newline
[ <body> newline
[ <h3> {HTML Comments} </h3> newline
[ para
[ <p> {The HTML code for the preceding
{ paragraph looks like this:}
[ html-escape para
[ </p> newline
[ </body> newline
[ </html> newline
[ ]
<html>
<head> <title> Sample </title> </head>
<body>
<h3> HTML Comments </h3>
<p>This is a paragraph
<!-- Hello, world! -->
with an HTML comment
in the middle</p>
<p> The HTML code for the preceding
paragraph looks like this: <pre>
<p>This is a paragraph
<!-- Hello, world! -->
with an HTML comment
in the middle</p>
</pre> </p>
</body>
</html>
...which, of course, you could also write to a file.
Hope this helps!
-jn-
[7/11] from: tim:johnsons-web at: 29-Oct-2000 19:16
Yes, Joel, this is right on!
Thanks
-Tim
Joel Neely wrote:
[8/11] from: tim:johnsons-web at: 29-Oct-2000 19:22
Hi Al:
[Al--Bri--xtra--co--nz] wrote:
> I've got a much nicer version of R2HTML.r on my home computer which I must post to
Rebol.org...
Please do, Al. The more good rebol code out there the better. What makes perl attractive
to
newbies is the archives and the free legacy stuff.
Once you folks square me away a few more times, I will have a CGI library to post. There
are some cross-platform gotchas, I am finding, and resolving as I switch over from C/C++.
Thanks
Tim
[9/11] from: al::bri::xtra::co::nz at: 30-Oct-2000 17:23
Joel Neely wrote:
> Ah! Now I understand. Yes, the bottom-level solution is the HTML
entities that are "escapes" for < and >. However, you can REBOLize the
process, as illustrated in the following:
You also need to account for Named Entities as well:
Named_Entities: [
"quot" "amp" "lt" "gt" "nbsp" "iexcl" "cent" "pound" "curren"
"yen" "brvbar" "sect" "uml" "copy" "ordf" "laquo" "not" "shy"
"reg" "macr" "deg" "plusmn" "sup2" "sup3" "acute" "micro"
"para" "middot" "cedil" "sup1" "ordm" "raquo" "frac14"
"frac12" "frac34" "iquest" "times" "Oslash"
]
Replace_Named_Entities: func [Script [string!]] [
Map Named_Entities func [Entity] [
replace/all Script join "&" Entity join "&"
[Amp_Entity_Replacement Entity]
]
Script
]
; A temporary replacement for "amp;" to avoid infinite recursion.
; Don't simplify! Why? The constant will be replaced when this program
is converted to HTML!
Amp_Entity_Replacement: join "a" "R2HTMLmR2HTMLpR2HTML;" ; "amp;"
with "R2HTML" between each letter.
Replace_Entities: func [Script [string!]] [
replace/all Script "&#" join "&" [Amp_Entity_Replacement "#"]
Script: Replace_Named_Entities Script
replace/all Script "<" "<"
replace/all Script ">" ">"
replace/all Script Amp_Entity_Replacement "amp;"
Script
]
Andrew Martin
Who did this, way, way back...
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
[10/11] from: al:bri:xtra at: 30-Oct-2000 17:34
Tim wrote:
> Andrew wrote:
> > I've got a much nicer version of R2HTML.r on my home computer which I
must post to Rebol.org...
> Please do, Al.
Well, I've done so, but the Rebol.org bot doesn't seem to be working. :-( So
I've posted it to my site, here:
http://members.nbci.com/AndrewMartin/Rebol/
It's in the R2Html sub-directory, along with some other stuff.
> The more good rebol code out there the better. What makes perl attractive
to newbies is the archives and the free legacy stuff.
This needs to happen with Rebol as well.
> Once you folks square me away a few more times, I will have a CGI library
to post. There are some cross-platform gotchas, I am finding, and resolving
as I switch over from C/C++.
Sounds great!
Andrew Martin
Still working on a Rebol modular/OO webserver/Wiki/Sparrow...
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
[11/11] from: joel:neely:fedex at: 30-Oct-2000 6:36
Hi, Andrew,
I guess we were solving different problems. I understood the task
to be
Take a fragment of HTML and convert it so that it appears
literally in the visitor's browser.
That means that I explicitly didn't want entities protected, but
rather wanted their ampersands converted to & so that the
visitor's browser would display the "raw" entity code, and not
the entity replacement value.
-jn-
[rebol-bounce--rebol--com] wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted