W3C home > Mailing lists > Public > html-tidy@w3.org > January to March 2016

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

From: Richard A. O'Keefe <ok@cs.otago.ac.nz>
Date: Tue, 12 Jan 2016 16:47:05 +1300
CC: <html-tidy@w3.org>
Message-ID: <EF662761-9806-447F-9A00-D41C3B069035@cs.otago.ac.nz>
To: Jinkai Wang <jinkai.wang@oracle.com>

On 9/01/2016, at 8:29 am, Jinkai Wang <jinkai.wang@oracle.com> 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:
> rnt_tidy (buf_in=0x933b430 "<DIV><SPAN STYLE=\"font-family:System Default;\">hello world : item 1\nitem 2\nitem 3. Finish</SPAN></DIV><DIV><SPAN STYLE=\"font-family:System Default;\">Jinkai Hello World</SPAN></DIV>", buf_out=0x9311690, bad_tag_check=1, tidy_opts_ptr=0xfff97114)

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="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="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.
Received on Tuesday, 12 January 2016 03:47:42 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 12 January 2016 03:47:45 UTC