Forum


Replies: 11   Views: 2823
Handling of lists..
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 26-09-2019 - 10:21

Hello,

The problem seems a Tidy problem that is adding extra tags (https://stackoverflow.com/questions/8533204/prevent-html-tidy-adding-li-elements), although testing for example using PHP 7.3 no extra LI tag is added and the output is perfect.

Using a Premium license and HTML Extended it can be easily done:

$html = '
<ul class="textbox-list">
    <li>Have you heard of this animal before?</li>
    <phpdocx_break data-type="line" data-number="5" />
    <li>What do you already know about this animal?</li>
    <phpdocx_break data-type="line" data-number="5" />
</ul>
';
$docx->embedHTML($html, array('useHTMLExtended' => true));

But as you are using an Advanced license, you could try updating to PHP 7.3 to check if the Tidy issue is solved automatically, or use an alternative approach compatible with all PHP versions:

$html = '
<ul class="textbox-list">
    <li>Have you heard of this animal before?$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$</li>
    <li>What do you already know about this animal?$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$$VAR_BREAK$</li>
</ul>
';
$docx->embedHTML($html);
$docx->createDocx('output_t');

$docxT = new Phpdocx\Create\CreateDocxFromTemplate('output_t.docx');
$wordFragment = new Phpdocx\Elements\WordFragment($docx);
$wordFragment->addBreak();
$docxT->replaceVariableByWordFragment(array('VAR_BREAK' => $wordFragment), array('type' => 'inline'));
$docxT->createDocx('output.docx');

This code adds VAR_BREAK placeholders and then open the output as template to replace those placeholders by line breaks. You could also use DOCXPath [https://www.phpdocx.com/api-documentation/docx-path/replace-elements-in-docx] to avoid generating a template and do all steps using only the CreateDocx class.

Regards.