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

Html to Docx issues #543

Closed
patrickbrouwers opened this issue Jun 4, 2015 · 1 comment
Closed

Html to Docx issues #543

patrickbrouwers opened this issue Jun 4, 2015 · 1 comment

Comments

@patrickbrouwers
Copy link

patrickbrouwers commented Jun 4, 2015

Thanks for this great package!

I'm having issues converting html to docx.

I get user input in Markdown and convert this to html with https://github.com/thephpleague/commonmark

Input:

text
text

text
text

Gets converted to:

<p>text
text</p>

<p>text
text</p>

In the Word-document it will look like:

text text
text text

This behaviour seems logical when I read the code. All linebreaks get deleted and html linebreaks (<br /> get ignored).

By adding a method that parses the br's (I added with nl2br), it works just like I would expect.

I'm wondering if this is the best way of handling it (and if this could be added to the package) or if there's a better way of handling it?

Any help would be appreciated. Happy to make a pull request if needed.


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

@patrickbrouwers
Copy link
Author

In the meantime I found out that (for my use case) this is the best solution:

/**
     * Parse paragraph node
     *
     * @param \DOMNode $node
     * @param \PhpOffice\PhpWord\Element\AbstractContainer $element
     * @param array &$styles
     * @return \PhpOffice\PhpWord\Element\TextRun
     */
    private static function parseParagraph($node, $element, &$styles)
    {
        $styles['paragraph'] = self::parseInlineStyle($node, $styles['paragraph']);
        $newElement = $element->addTextRun($styles['paragraph']);
        $newElement->addTextBreak(1);

        return $newElement;
    }

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

1 participant