Hyperlink rendering uses the style of the last run for all runs

I’ve observed that when using multiple runs in an internally linking hyperlink, that the style of the final run is used for all runs. This can be seen as the following XML:

        <w:p>
            <w:hyperlink w:anchor="bookmark_id">
                <w:r>
                    <w:t xml:space="preserve">Regular display text </w:t>
                </w:r>
                <w:r>
                    <w:rPr>
                        <w:b/>
                    </w:rPr>
                    <w:t>but this is bold</w:t>
                </w:r>
            </w:hyperlink>
        </w:p>

In this, I’d expected that the content “but this is bold” has bold applied, while the rest has default styling.

In reality all of the text has bold applied as seen in the attached image.

If I include another run with no styling, then all items render as expected.

        <w:p>
            <w:hyperlink w:anchor="bookmark_id">
                <w:r>
                    <w:t xml:space="preserve">Regular display text </w:t>
                </w:r>
                <w:r>
                    <w:rPr>
                        <w:b/>
                    </w:rPr>
                    <w:t>but this is bold</w:t>
                </w:r>
                <w:r>
                    <w:t xml:space="preserve"> and this is not</w:t>
                </w:r>
            </w:hyperlink>
        </w:p>

The following image shows the two hyperlinks in writer:
image

These documents are created programmatically, and therefore solutions requiring the user interface are not feasible resolutions.
Currently I’ve found the following workarounds:

  • Ensure there is a run with no styling and content present as the last run
  • Explicitly set formatting to off ( <w:b w:val=“0”/> )

Is this something I am overlooking or should I report a bug? I’d expect that only runs with formatting explicitly applied would receive the formatting and this is the case in other editors such as OnlyOffice.

This is on version 25.2.5.2.

Cheers!

Even if you format programmatically, you should follow the general LO philosophy, i.e. Styles. I see no style application in your snippet. Where do you switch from regular to Bold and back?

No need to ask here.

You see something that doesn’t work as per spec?
Or you see that the reference application handles that differently? (Of course you tested how Word renders the OOXML you present, didn’t you?)

Then just file a bug.
And there, don’t limit to the OOXML snippets. Add your (generated) DOCX. People must not have to re-create the document manually to see the problem. Just as here on the Ask; you only provided a code and a PNG, but e.g. I’m not inclined to do the work of creating a sample to verify in different LO versions and in Word.

EDIT: OK, I lied, I was inclined. Filed tdf#167682. Note that this is a regression in 24.8.

2 Likes

Thank you!

I’ll just directly file bugs for this kind of thing in the future :slight_smile: