Re: How can we support in-block newline break preservation

"Richard A. O'Keefe" <[email protected]> Tue, 12 Jan 2016 16:47:05 +1300
Newsgroups gmane.comp.web.html-tidy.user
Message-ID <[email protected]>
On 9/01/2016, at 8:29 am, Jinkai Wang <[email protected]> wrote:

> To whom it may concern,
> I'm an application developer from Oracle Service Cloud. Recently we =
have a concern about how to have the tidy  preserve line breaks in a =
multi-line text.
> For example, this is the input:
>=20
> rnt_tidy (buf_in=3D0x933b430 "<DIV><SPAN STYLE=3D\"font-family:System =
Default;\">hello world : item 1\nitem 2\nitem 3. =
Finish</SPAN></DIV><DIV><SPAN STYLE=3D\"font-family:System =
Default;\">Jinkai Hello World</SPAN></DIV>", buf_out=3D0x9311690, =
bad_tag_check=3D1, tidy_opts_ptr=3D0xfff97114)

Tidy respects (or at least tries very hard to respect)
HTML semantics.  <div><span>...</span></div> is *not*
a context where HTML semantics preserves white space.

Since *browsers* don't preserve line breaks in this context,
it is unclear why you want Tidy to do so.

If the input is well-formed XML, you can force white space
preservation by
(1) adding the xml:space=3D"preserve" attribute to the
element(s) where you want this to happen and
(2) telling tidy that the input is -xml

This should work in a browser too.

Alternatively, if there is a <span> where you want line breaks
preserved, use a <pre> instead.  The semantics of HTML require
line breaks preserved in <pre> elements.

This will work in a browser too.

For display purposes, you can use style=3D"white-space: pre" to
force line breaks to be preserved and white space not to be
collapsed.  By experiment, Tidy doesn't notice that and will
do its own white-space processing.  (This is CSS semantics,
not HTML semantics, hence the difference.)

I suspect that the fundamental problem is not with Tidy but
with the way you are using HTML.