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

Ordered Lists from HTML don't restart numbering #508

Closed
jelofson opened this issue Mar 20, 2015 · 11 comments
Closed

Ordered Lists from HTML don't restart numbering #508

jelofson opened this issue Mar 20, 2015 · 11 comments

Comments

@jelofson
Copy link

jelofson commented Mar 20, 2015

Have a loop which inserts html from a database. When a second ordered list is added (in a new section), the numbering does not restart. For example:

foreach ($rows as $row) {
    $section->addTitle(htmlspecialchars($row->title), 2);
    \PhpOffice\PhpWord\Shared\Html::addHtml($section, $row->somehtml);
}

Might result in something like this:

Section Title
bla bla

  1. list item
  2. list itme

New section title
text bla bla
3. list item
4. list item

I have to go into Word to manually set the starting number to 1.

I will see if I can dig into the code and find where this is set.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@inimist
Copy link

inimist commented Jan 28, 2016

This issue persists. In addition it does not allow any html tags inside <li></li>. Does anyone got a fix to it?

@AcademyLime
Copy link

+1

1 similar comment
@pankamilr
Copy link

+1

@metallurgical
Copy link

seems like the issue still persists

@pankamilr
Copy link

In my issue I've made new Class extends HTML class and then create new overwrites to make this work. I have to test this once again and if nothing goes wrong I could commit changes to repo.

@metallurgical
Copy link

@pankamilr looking forward on it. As i need them urgently.

@pankamilr
Copy link

pankamilr commented Dec 13, 2017

@metallurgical I create a gist with it. Please take a look if you need it and let me know if its good for your
PhpWord.HTML.php

@samimussbach
Copy link

@pankamilr this looks really promising! You made a lot of changes which makes it a bit hard to understand and test. It looks like your gist tackles quite a bunch of long lasting problems.
Would you mind to tear those problems into more atomical pull requests? Perhaps this would make it easier to review and test your improvements.
Thanks for your work, at least it is a valuable source to point to the right directions where and what to improve.

@samimussbach
Copy link

I do not yet understand enough of the arcane magic of numbering in docx but I try to push a fix to this very old and obviously hard to tackle bug by providing a test.

I read quite a lot in the numbering issues (like e.g. as far as I know never fixed #10 and #193) and I think at least I understood, that the numId of two HTML ordered lists that should not share a numbering must always be different. This is what is tested.

Please correct me if I am wrong, maybe someone could guide me into some direction where and how to fix this. I am willing to try to do it, I just didn't manage to succeed.

    /**
     * Tests parsing of ul/li
     */
    public function testOrderedListNumbering()
    {
        $phpWord = new \PhpOffice\PhpWord\PhpWord();
        $section = $phpWord->addSection();
        $html = '<ol>
                <li>List 1 item 1</li>
                <li>List 1 item 2</li>
            </ol>
            <p>Some Text</p>
            <ol>
                <li>List 2 item 1</li>
                <li>List 2 item 2</li>
            </ol>';
        Html::addHtml($section, $html, false, false);

        $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
        $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
        $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));

        $this->assertEquals('List 1 item 1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
        $this->assertEquals('List 2 item 1', $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:t')->nodeValue);

        $firstListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId', 'w:val');
        $secondListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:numPr/w:numId', 'w:val');

        $this->assertNotEquals($firstListnumId, $secondListnumId);
    }

@troosan
Copy link
Contributor

troosan commented Jan 13, 2018

fixed in develop (0.15.x)

@troosan troosan closed this as completed Jan 13, 2018
@kczereczon
Copy link

PDF Writer is not adding numbering used dompdf

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

8 participants