How can we support in-block newline break preservation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How can we support in-block newline break preservation

Jinkai Wang
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)

Here we have a text field with three lines:
item 1
item 2
item 3

However, after passing through tidy, it becomes:
rnt_tidy rnt_tidy.c:381 [TRLEV1]: FINAL buffer at EOF is: <div><span
style="font-family:System Default;">hello world : item 1 item 2 item 3.
Finish</span></div>

the   newline character '\n' becomes a  space, I just wonder if the tidy
has an option or feature to support the preservation of newline character?

I tried  ( TidyLiteralAttribs,  yes)  and ( TidyXmlSpace, yes), but does
not work

Thanks
Jinkai


Reply | Threaded
Open this post in threaded view
|

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

Richard A. O'Keefe
PS: the subject line has me confused as well.
<span> is an in-LINE element.
<div> is a BLOCK element.
What is an "IN-BLOCK" element?



Reply | Threaded
Open this post in threaded view
|

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

Richard A. O'Keefe
In reply to this post by Jinkai Wang

On 9/01/2016, at 8:29 am, Jinkai Wang <[hidden email]> 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.


Reply | Threaded
Open this post in threaded view
|

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

Jinkai Wang
Thanks Richard, the introduction of tidy is actually not done by me. I
will discuss with my colleagues to decide which way we are going.

Jinkai

On 1/11/2016 7:47 PM, Richard A. O'Keefe wrote:

> On 9/01/2016, at 8:29 am, Jinkai Wang <[hidden email]> 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.
>


Reply | Threaded
Open this post in threaded view
|

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

Geoff McLane
In reply to this post by Richard A. O'Keefe
Sorry for the delay in my reply, but I was quite confused by the
question so did not know how to answer.

Basically HTML Tidy is HTML parser and tidier. Normally it will remove
all newline breaks in text, and replace them with a space, unless the
text is wrapped in a block element that preserves them, like a PRE, just
like a browser...

So I do not think Tidy is likely to support newline breaks in normal
text, but as said maybe I do not understand the question!


Reply | Threaded
Open this post in threaded view
|

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

Richard A. O'Keefe
On 8/03/16 8:14 am, Geoff McLane wrote:
> So I do not think Tidy is likely to support newline breaks in normal
> text, but as said maybe I do not understand the question!

Actually, it does.  Sort of.  If you use the command line option -xml
you can use the xml:space="preserve" attribute on an element and
Tidy5 will not reflow the text of that element.  By actual test, you
can even do <html xml:space="preserve">.

Just to repeat: the input *has* to be well formed XML for this to
work; if you tell Tidy5 the input is good XML and it isn't, you are
to blame for whatever happens.



Reply | Threaded
Open this post in threaded view
|

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

Carmen Ramirez

Ramirez044@yahoo,com

On Mar 7, 2016 4:24 PM, "Richard A. O'Keefe" <[hidden email]> wrote:
On 8/03/16 8:14 am, Geoff McLane wrote:
So I do not think Tidy is likely to support newline breaks in normal text, but as said maybe I do not understand the question!

Actually, it does.  Sort of.  If you use the command line option -xml
you can use the xml:space="preserve" attribute on an element and
Tidy5 will not reflow the text of that element.  By actual test, you
can even do <html xml:space="preserve">.

Just to repeat: the input *has* to be well formed XML for this to
work; if you tell Tidy5 the input is good XML and it isn't, you are
to blame for whatever happens.




.sdinfo (110 bytes) Download Attachment