Table of Contents
Create bookmarks, hyperlinks, and cross-references within a document.
1. Creating Bookmarks
# Create bookmark
bookmark = Uniword::Bookmark.new(
id: 1,
name: 'Section1'
)
para = Uniword::Paragraph.new
para.add_text("Bookmarked section")
para.add_bookmark_start(bookmark)
para.add_bookmark_end(bookmark.id)
doc.bookmarks << bookmark
doc.add_element(para)
Each bookmark needs a unique id (integer) and a name (string). The bookmark
start and end markers wrap the content you want to reference.
2. Adding Hyperlinks
Use the hyperlink option to link to external URLs or internal bookmarks:
# External hyperlink
para = Uniword::Paragraph.new
para.add_text("Visit ")
para.add_text("our website", hyperlink: 'https://example.com')
# Internal cross-reference to bookmark
para = Uniword::Paragraph.new
para.add_text("See ")
para.add_text("Section 1", hyperlink: '#Section1')
doc.add_element(para)
|
When linking to a bookmark within the same document, prefix the bookmark name with |