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 - Inline Span Style Changes Not Recognised - With a solution #414

Open
mogilvie opened this issue Nov 9, 2014 · 2 comments

Comments

@mogilvie
Copy link

mogilvie commented Nov 9, 2014

Hi,

I had text within an HTML table cell that was styled using a <span> element. None of these styles were being parsed through to the phpWord DOM.

I got them working by introducing a <span> node type in the \PhpWord\Shared\Html.php parseNode method.

        // Node mapping table
        $nodes = array(
                              // $method        $node   $element    $styles     $data   $argument1      $argument2
            'p'         => array('Paragraph',   $node,  $element,   $styles,    null,   null,           null),
            'h1'        => array('Heading',     null,   $element,   $styles,    null,   'Heading1',     null),
            'h2'        => array('Heading',     null,   $element,   $styles,    null,   'Heading2',     null),
            'h3'        => array('Heading',     null,   $element,   $styles,    null,   'Heading3',     null),
            'h4'        => array('Heading',     null,   $element,   $styles,    null,   'Heading4',     null),
            'h5'        => array('Heading',     null,   $element,   $styles,    null,   'Heading5',     null),
            'h6'        => array('Heading',     null,   $element,   $styles,    null,   'Heading6',     null),
            '#text'     => array('Text',        $node,  $element,   $styles,    null,    null,          null),
            'span'      => array('Span',        $node,  null,       $styles,    null,    null,          null), //to catch inline span style changes
            'strong'    => array('Property',    null,   null,       $styles,    null,   'bold',         true),
            'em'        => array('Property',    null,   null,       $styles,    null,   'italic',       true),
            'sup'       => array('Property',    null,   null,       $styles,    null,   'superScript',  true),
            'sub'       => array('Property',    null,   null,       $styles,    null,   'subScript',    true),
            'table'     => array('Table',       $node,  $element,   $styles,    null,   'addTable',     true),
            'tbody'     => array('Table',       $node,  $element,   $styles,    null,   'skipTbody',    true), //added to catch tbody in html.
            'tr'        => array('Table',       $node,  $element,   $styles,    null,   'addRow',       true),
            'td'        => array('Table',       $node,  $element,   $styles,    null,   'addCell',      true),
            'ul'        => array('List',        null,   null,       $styles,    $data,  3,              null),
            'ol'        => array('List',        null,   null,       $styles,    $data,  7,              null),
            'li'        => array('ListItem',    $node,  $element,   $styles,    $data,  null,           null),
        );

I then added a new method to the same class called parseSpan:

    /**
     * Parse span
     * 
     * Changes the inline style when a Span element is found.
     * 
     * @param type $node
     * @param type $element
     * @param array $styles
     * @return type
     */
    private static function parseSpan($node, &$styles)
    {
        $styles['font'] = self::parseInlineStyle($node, $styles['font']);        
        return null;        
    }

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

@mogilvie mogilvie changed the title HTML to WordML - Inline Span Style Changes Not Recognised HTML to Docx - Inline Span Style Changes Not Recognised Nov 9, 2014
@mogilvie mogilvie changed the title HTML to Docx - Inline Span Style Changes Not Recognised HTML to Docx - Inline Span Style Changes Not Recognised - With a solution Nov 11, 2014
@GoldenRocking
Copy link

this method not work

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
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