Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior when parsing html tag 'br' #1325

Closed
1 of 3 tasks
GolDiV opened this issue Mar 29, 2018 · 5 comments
Closed
1 of 3 tasks

Incorrect behavior when parsing html tag 'br' #1325

GolDiV opened this issue Mar 29, 2018 · 5 comments

Comments

@GolDiV
Copy link

GolDiV commented Mar 29, 2018

This is:

Expected Behavior

When I use the tag <br/> in html string and parse it in phpword like addHtml('test1<br/>test2'), in MsWord I expect to recieve next:
'test1' (soft line break like 'shift+enter')
'test2'

Current Behavior

But now it work as next:
'test1' (line break like 'enter')
'empty string' (line break like 'enter')
'test2'

Failure Information

An empty string is inserted because function 'parseLineBreak' in class 'html' do it ($element->addTextBreak();). If this function is made empty, then the extra line will disappear. However, where to replace line break to soft line break, I did not find

How to Reproduce

Please provide a code sample that reproduces the issue.

<?php
require __DIR__ . '/vendor/autoload.php';

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$html ='test1<br/>test2';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);

Context

  • PHP version: 7.1
  • PHPWord version: 0.15
@troosan
Copy link
Contributor

troosan commented Mar 29, 2018

Did you try the dev-develop version?

@GolDiV
Copy link
Author

GolDiV commented Mar 29, 2018

yes

@troosan
Copy link
Contributor

troosan commented Apr 1, 2018

If you parse the following it's fine

<p>test1<br/>test2</p>

@troosan troosan closed this as completed Apr 21, 2018
@apothan
Copy link

apothan commented Apr 26, 2018

@troosan Is it expected that you use the paragraph tag around any HTML added this way? I am getting the same issue as OP. I do not use the paragraph tag because it creates formatting I do not want.

This seems to have been introduced in 0.14 because if I go back to 0.13 it does not happen.

@troosan
Copy link
Contributor

troosan commented Apr 29, 2018

I'll see if I can restore backward compatibility.
I guess I could automatically add a <p> if the root element is not a block element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants