Managing White Space in XHTML

Is there any information on how to properly handle spaces in XHTML (1.0 Transitional)? XHTML does not seem to use standard XML white space processing.

Edit: Maibi, I was a little inaccurate about what I was exactly looking for. I'm more interested in how an element is rendered than how it will be processed by an XML processor. For example, the following will be displayed with 1 space in between:

<em> em content </em> following text 

The situation becomes more complicated if the space actually has its own formatting, for example, <a href="http://www.google.de"> content of the hyperlink </a> content after the hyperlink will have an underlined space at the end of the hyperlink, and <a href="http://www.google.de"> content of the hyperlink</a> content after the hyperlink<br /> will not underline the space.

It seems that space is always added to the previous formatting area, and spaces are handled by (built-in) elements of the start and end tags. But this is based solely on testing, and I was wondering if there was any specification on how this behaves well.

+4
source share
2 answers

There seems to be no real documentation on how white spaces are displayed in XHTML. Here is what I learned from the experiment:

  • White spaces are reduced to the same space, even at the beginning and end of tags inside the same block.
  • The space will be placed in the formatting area of ​​the containing tag. If it spans two tags, it will be added to the first tag.
  • Spaces at the beginning and end of block elements or span elements that are the first child / last child in their block are ignored.
  • White spaces outside block elements are ignored.

That is all I could understand. It is sad that the XHTML specification does not contain information about rendering white spaces.

+1
source

From the W3C Recommendation :

4.7. White space handling in attribute values

When user agents process attributes, they do this according to Section 3.3.3 of [XML]:

  • The strip leading and completing the white space.
  • Card sequences of one or more space characters (including line breaks) in a single interlayer space.

For spaces between tags see section section 3.2 criteria 9:

3.2. User Agent Alignment

[1-8 snipped]

9. White space is processed in accordance with the following rules. The following characters are defined in space characters [XML]:

  • SPACE (&#x0020;)
  • HORIZONTAL TABULATION (&#x0009;)
  • RETURN (&#x000D;) SHIPPING (&#x000D;)
  • LINE FEED (&#x000A;)

The XML processor normalizes the end-line codes of various systems into a single LINE FEED character, which is passed to the application.

The user agent must use the CSS definition to handle whitespace [CSS2]. Note that CSS2's recommendation does not explicitly address the issue of handling spaces in non-Latin character sets. This will be discussed in a future version of CSS, after which this link will be updated.

Also see section C.15 :

P .15. White space characters in HTML and XML

Some characters that are legal in HTML documents are illegal in an XML document. For example, in HTML a Formfeed character (U + 000C) is treated as a space, in XHTML, because of the XML character characters, it is illegal.

+3
source

Source: https://habr.com/ru/post/1309802/


All Articles