Skip to content

Unexpected behavior of 'add-xml-space' setting when used with 'wrap' => 0 and saveBuffer is called twice in tidy-html5 5.6.0 #673

@TysonAndre

Description

@TysonAndre

I'm using the PHP tidy wrapper(PHP 7.1.14) and the tidy HTML5 5.6.0 release

The behavior is different from 5.4.0. Tidy is inserting an excessive amount of newlines when those two options are used together.

Additionally, the behavior seems to contradict the documentation for 'tidy' => 0

This option specifies the right margin Tidy uses for line wrapping. Tidy tries to wrap lines so that they do not exceed this length. Set wrap to zero if you want to disable line wrapping.

It seems like https://github.com/htacg/tidy-html5/pull/645/files#diff-4a4e354609aef4a160784a5caa18e868R1710 might be a cause, but that's just an uninformed guess. (It looks like code that adds a newline).

php > $x = new Tidy();$x->parseString('<p>this is a string</p>', ['add-xml-space' => true, 'show-body-only' => true, 'wrap' => 50], 'utf8'); echo (string)$x;
<p>this is a string</p>
php > $x = new Tidy();$x->parseString('<p>this is a string</p>', ['add-xml-space' => true, 'show-body-only' => true, 'wrap' => 0], 'utf8'); echo (string)$x;
<p>
this
is
a
string</p>

A workaround is to set 'wrap' to an extremely large integer. This will continue to preserve newlines without breaking up long lines

$x = new Tidy();$x->parseString('<p>this is a string</p>', ['add-xml-space' => true, 'show-body-only' => true, 'wrap' => (1 << 30)], 'utf8'); echo (string)$x;
<p>this is a string</p>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions