Re: how to create a MultiLine string
- From: "Richard Cornford" <Richard@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 26 Aug 2007 17:10:30 +0100
Thomas 'PointedEars' Lahn wrote:
Peter Michaux wrote:<snip>On Aug 24, 12:23 am, Douglas Crockford wrote:
var html = "<html>" +
"<body>" +
"<\/body>" +
"<\/html>";
Why escape the '/' on the closing tags? I have only read
that is necessary for script tags.
Your information is inaccurate.
Probably more superficial than inaccurate. To date there have been no
reports of an browsers that actually terminated CDATA SCRIPT element
contents just on the first occurrence of ETAGO, they seem to all wait
for ETAGO followed by (case folded) 'SCRIPT'. But, as usual, a failure
to observe (or observe and report) is not an indicator of the
non-existence of the thing that has not been observed. There may be, in
the past, currently or in the future, a browser that does behave
precisely as described in the HTML 4 specifications and will terminate
CDATA at the very first ETAGO, and HTML authors have no justification
for being surprised when/if that does happen.
CDATA content ends at an ETAGO delimiter,
no matter the element.
http://www.w3.org/TR/html4/types.html#type-cdata
That would be in HTML, according to the HTML speciation. The SGML
specification seems to have a different attitude, where it says (ISO
8879, Appendix B.13.1.1):-
| If an element contains declared character data, it cannot
| contain anything else. The markup parser scans it only to
| locate an ETAGO or NET; other markup is ignored. Only the
| correct end-tag (or that of an element in which this element
| is nested) will be recognised.
- which says that although the parser is looking for ETAGO it is only
interested in them if they start the "correct end-tag", or the end-tag
of a containing element. Given that the closing SCRIPT tag is not
optional (in HTML) it could be suggests that a hypothetical SGML parser
would skip '</'s until it found </script>. On the other hand it may be
that if the opening script was in, say, the HEAD the character sequence
'</head>' might be taken as "that of an element in which this element is
nested" and used to terminate the CDATA.
On the whole it has got to be safest to break up all occurrences of
ETAGO inside CDATA in HTML documents, and so satisfy all interpretations
of all applicable documents.
(It is also worth noting that ISO 8879 Appendix B is explanatory text
not reference.)
Do HTML parsers exist that have a problem with those
closing tags
Yes, the W3C Validator's SGML parser being one of them.
or are you just being conservative?
Maybe that as well.
There is no harm in being conservative here.
It is not necessary to escape ETAGOs if they do not
occur within `script' element CDATA content.
Aren't they just as potentially problematic in any other element's CDATA
contents (STYLE?)
So the said snippet has the<snip>
best chance to work everywhere.
I find it a easier to use single quotes when quoting HTML
because then attribute double quotes don't need escaping.
"<li id=\"foo\">"
'<li id="foo">'
Add me.
As do I, but not for that reason. It is a habit I acquired writing JSP,
where javascript and Java may appear together. I wanted the two to be as
visual distinct as possible (even though the syntax highlighting rules
for JSP apply the same rules to all code seen) and given that Java
string literals must be delimited with double quotes using single quotes
with javascript meant that if chunks of code contained sequences of text
characters in one color they were Java, and another color meant
javascript. A very immediate indicator of which code context you are
looking at in a JSP.
<snip>
(Unfortunately, the SGML spec is not available free<snip>
of charge at ISO.)
Anyone considering paying for a copy of an ISO specification would be
well advised to get their copy in electronic form. Although I much
prefer reading documents from paper (rather than a computer screen) the
quality of the ISO printed documents is not particularly good (read
'quite bad', even (ironically for the ISO) 'substandard') and it would
not take much work to achieve a superior hard copy from a printout of
the electronic version.
Richard.
.
- References:
- how to create a MultiLine string
- From: 魏中华
- Re: how to create a MultiLine string
- From: Evertjan.
- Re: how to create a MultiLine string
- From: weizhonghua.ati
- Re: how to create a MultiLine string
- From: Douglas Crockford
- Re: how to create a MultiLine string
- From: Peter Michaux
- Re: how to create a MultiLine string
- From: Thomas 'PointedEars' Lahn
- how to create a MultiLine string
- Prev by Date: Re: third-party libraries
- Next by Date: Re: third-party libraries
- Previous by thread: Re: how to create a MultiLine string
- Next by thread: Re: how to create a MultiLine string
- Index(es):
Relevant Pages
|