Printing HTML

May 16, 2005 23:47

I'm so pleased this community has been resurrected. To start the ball rolling:

curiosity about printing HTML )

Leave a comment

Comments 6

jc May 16 2005, 23:16:39 UTC
HTML tag attribute values should be encased in either single or double quotes, doesn't seem to matter which. I think the XHTML spec tightened that up to require double quotes, though.

To me, the print command is a courtesy at least when using ", in order to distinguish between printed strings and string variable assignments. I tend to ignore the print command when printing triple-quote strings, although println is handy to use in case you can't be bothered typing \n at the end of your single-quote string.

Reply


isabeau May 16 2005, 23:43:41 UTC
"foo" and """foo""" are in many respects the same thing; they're both strings. A string on a line by itself is an implicit print command, basically, although I often see print used with the single-quote version and not with the triple-quote version.

The "foo" version doesn't allow you to have quotes -- you can do print "foo"+otherstuff+"bar";, which means that if you want to print quotes within the string, you either need to escape it by using \" instead of " (some sample text), or need to use single-quotes, which don't count as the end-of-string marker ((some sample text)

I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.

The primary advantage, at least to my mind, of the triple-quote version is that you don't need to escape the quotes. (Especially since I've trained myself into -format HTML tags, and retraining myself to either use ' or \" is annoying.) I'll also often ( ... )

Reply

lithiana May 17 2005, 00:49:34 UTC
I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.

i'm sure i read somewhere that you couldn't do this with single quotes, but i just tried it, and you can. so who knows...

Reply

isabeau May 17 2005, 01:27:57 UTC
(and yes I am a dork and forgot a tag somewhere in there but I'm too lazy to repost.)

Reply

88888888 May 18 2005, 21:37:18 UTC
I definitely can't remember to escape my single-quotes, so I always go ahead and use triple-quotes under the assumption that I'll end up with a single-quote in there somewhere and will throw things when the compiler yells at me for it.

Reply


kunzite1 May 17 2005, 06:30:39 UTC
yay for being a geek with no life.

1."moo";moo
2."""moo""";moo
3.print "moo";moo
4.print """moo""";moo
5.print " lj home"; lj home
6.print "lj home"; lj home
7.print """ lj home"""; lj home
8.print """ lj home"""; lj home
9.print """lj home""";lj home
10.print """lj home"""; lj home
11.print $.view;recent
12.print "$.view";recent
13.print """$.view""";recent
14.print "$this->title()
";compile error
15.print "" + $this->title() + "
";kunzite&39s krazy days

16.""; $this->title(); "
";

17.""; print $this->title(); "
";kunzite&39s krazy days

ok... i think that's enough.

1-4 are effectively identical.
5 & 7 are effectively identical.
6, 8, and 10 are effectively identical.
9 is kinda silly.
11-13 are effectively identical. they also assume you are in RecentPage. RecentPage.view is a string.
15 & 17 are effectively identical.
15-17 assume you are in a *Page. Page::title() returns a string.

in 3-13, print can be removed and still have the same result.

Reply


Leave a comment

Up