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

[BUGFIX] Handle direct and nested title text paths #2598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sbuerk
Copy link
Contributor

@sbuerk sbuerk commented Apr 2, 2024

It seems that in newer formats it's possible that the
w:r for an pStyle can be deeper nested as a sibling
of the parent note.

Older versions:

<w:p
    w:rsidR="00000000" w:rsidDel="00000000"
    w:rsidP="00000000" w:rsidRDefault="00000000"
    w:rsidRPr="00000000" w14:paraId="00000001">
    <w:pPr>
        <w:pStyle w:val="Heading1"/>
        <w:rPr/>
    </w:pPr>
    <w:r w:rsidDel="00000000" w:rsidR="00000000"
         w:rsidRPr="00000000">
        <w:rPr>
            <w:rtl w:val="0"/>
        </w:rPr>
        <w:t xml:space="preserve">Überschrift 1</w:t>
    </w:r>
</w:p>

versu newer versions:

<w:p w14:paraId="64815DFA" w14:textId="77777777"
     w:rsidR="002A1C92" w:rsidRDefault="00000000">
    <w:pPr>
        <w:pStyle w:val="berschrift1"/>
    </w:pPr>
    <w:sdt>
        <w:sdtPr>
            <w:id w:val="-1128864550"/>
            <w:placeholder>
                <w:docPart w:val="6F00E81731533248A49CB16AC5C3C3DE"/>
            </w:placeholder>
            <w:temporary/>
            <w:showingPlcHdr/>
            <w15:appearance w15:val="hidden"/>
        </w:sdtPr>
        <w:sdtContent>
            <w:r w:rsidR="00D04D7B">
                <w:t>Überschrift 1</w:t>
            </w:r>
        </w:sdtContent>
    </w:sdt>
</w:p>

Therefore, this change now uses a double check for the direct and the
nested variant to detect the content (text) of a title text section:

// old
    'w:r',
    $domNode
);

// new
    'w:r|w:sdt/w:sdtContent/w:r',
    $domNode
);

in \PhpOffice\PhpWord\Reader\Word2007\AbstractPart::readParagraph().

It seems that in newer formats it's possible that the
`w:r` for an pStyle can be deeper nested as a sibling
of the parent note.

Older versions:

```
<w:p
    w:rsidR="00000000" w:rsidDel="00000000"
    w:rsidP="00000000" w:rsidRDefault="00000000"
    w:rsidRPr="00000000" w14:paraId="00000001">
    <w:pPr>
        <w:pStyle w:val="Heading1"/>
        <w:rPr/>
    </w:pPr>
    <w:r w:rsidDel="00000000" w:rsidR="00000000"
         w:rsidRPr="00000000">
        <w:rPr>
            <w:rtl w:val="0"/>
        </w:rPr>
        <w:t xml:space="preserve">Überschrift 1</w:t>
    </w:r>
</w:p>
```

versu newer versions:

```
<w:p w14:paraId="64815DFA" w14:textId="77777777"
     w:rsidR="002A1C92" w:rsidRDefault="00000000">
    <w:pPr>
        <w:pStyle w:val="berschrift1"/>
    </w:pPr>
    <w:sdt>
        <w:sdtPr>
            <w:id w:val="-1128864550"/>
            <w:placeholder>
                <w:docPart w:val="6F00E81731533248A49CB16AC5C3C3DE"/>
            </w:placeholder>
            <w:temporary/>
            <w:showingPlcHdr/>
            <w15:appearance w15:val="hidden"/>
        </w:sdtPr>
        <w:sdtContent>
            <w:r w:rsidR="00D04D7B">
                <w:t>Überschrift 1</w:t>
            </w:r>
        </w:sdtContent>
    </w:sdt>
</w:p>
```

Therefore, this change now uses a double check for the direct and the
nested variant to detect the content (text) of a title text section:

```php
// old
    'w:r',
    $domNode
);

// new
    'w:r|w:sdt/w:sdtContent/w:r',
    $domNode
);
```

in `\PhpOffice\PhpWord\Reader\Word2007\AbstractPart::readParagraph()`.
@coveralls
Copy link

Coverage Status

coverage: 97.217%. remained the same
when pulling 289f57c on sbuerk:stefan-2
into 8b891bb on PHPOffice:master.

Copy link
Member

@Progi1984 Progi1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbuerk Hi, could you remove the @todo and update the changelog, please ?

@Progi1984 Progi1984 added the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Aug 15, 2024
@sbuerk
Copy link
Contributor Author

sbuerk commented Oct 11, 2024

@sbuerk Hi, could you remove the @todo and update the changelog, please ?

Sorry, was kind of busy with mainting other open source stuff, and will be until thusday. Will try to update this and my other pr's in the next 2 weeks, sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting for feedback Question has been asked, waiting for response from PR author
Development

Successfully merging this pull request may close these issues.

3 participants