Skip to content

Conversation

@Skelmis
Copy link
Owner

@Skelmis Skelmis commented Jun 15, 2025

Example code:

from skelmis.docx import Document

doc = Document()
p = doc.add_paragraph()
p.add_internal_hyperlink("bookmark", "goto bookmark")
doc.add_page_break()

p = doc.add_paragraph()
p.add_bookmark(
    "bookmark",
    "hey look its bookmark display text",
)

doc.save("test.docx")

Tested:
add_bookmark:

  • Libre
  • OnlyOffice

add_internal_hyperlink:

  • Libre
  • OnlyOffice

Closes #20

Initial reference implementation taken from various comments on: https://stackoverflow.com/questions/57586400/how-to-create-bookmarks-in-a-word-document-then-create-internal-hyperlinks-to-t

@Skelmis
Copy link
Owner Author

Skelmis commented Jun 15, 2025

PR is blocked until they work in Libre as well as we need that for PDF's...
Unsure why at a glance, it seems to be roughly correct syntax in the document.xml

@Skelmis
Copy link
Owner Author

Skelmis commented Jun 15, 2025

Lib generated:

        <w:p>
            <w:hyperlink w:anchor="bookmark" w:tooltip="tooltip">
                <w:r>
                    <w:rPr/>
                    <w:t>goto bookmark</w:t>
                </w:r>
            </w:hyperlink>
        </w:p>

Libre generated:

        <w:p>
            <w:pPr>
                <w:pStyle w:val="Normal"/>
                <w:rPr></w:rPr>
            </w:pPr>
            <w:hyperlink w:anchor="bookmark">
                <w:r>
                    <w:rPr>
                        <w:rStyle w:val="Hyperlink"/>
                    </w:rPr>
                    <w:t>#bookmark</w:t>
                </w:r>
            </w:hyperlink>
        </w:p>

@Skelmis
Copy link
Owner Author

Skelmis commented Jun 15, 2025

Wild, by not adding the tooltip Libre then recognises it as an internal hyperlink. If we set a tooltip then it fails to be recognised as a hyperlink

@Skelmis Skelmis marked this pull request as ready for review June 15, 2025 10:57
@Skelmis Skelmis merged commit 06f9b57 into master Jun 15, 2025
8 checks passed
@Skelmis Skelmis deleted the feat/bookmarking branch June 15, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update hyperlink documentation

2 participants