Association between ToC index object and its paragraph content

Miklos Vajna vmiklos at collabora.co.uk
Thu Dec 7 08:58:24 UTC 2017


Hi Jens,

On Thu, Dec 07, 2017 at 06:04:08AM +0100, Jens Tröger <jens.troeger at light-speed.de> wrote:
> While walking all paragraphs of a Writer document and visiting their text
> content, I come across text portions (the Heading N) which have Bookmarks
> whose name is something like “_Toc263250771”. However, when I walk the 
> paragraphs and text portions that actually make up the ToC of the document
> itself, I see no indication or reference to these bookmarks.

Let's say you have a ToC, then a Heading 1 paragraphs, Foo.

Then the ToC refers to hidden RefHeading bookmark for Foo. You can see
this reference at an UNO API level. Basic code for this:

oParas = ThisComponent.Text.createEnumeration
oPara = oParas.nextElement ' Table of Contents
oPara = oParas.nextElement ' Foo
oPortions = oPara.createEnumeration
oPortion = oPortions.nextElement
xray oPortion.HyperlinkURL ' gives #__RefHeading___Toc...

If you want to see the bookmarks the ToC refers to, it's similar:

...
oPara = oParas.nextElement ' Foo
oPortions = oPara.createEnumeration
oPortion = oPortions.nextElement
xray oPortion.TextPortionType ' gives Bookmark
xray oPortion.Bookmark.Name ' gives #__RefHeading___Toc...

In most cases if you see some information serialized into ODT, then you
can assume the same information is available via the UNO API. You can
always read (most of) the ODT filter in xmloff/ to see what exact UNO
API is used to write a given ODT markup.

Regards,

Miklos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20171207/69695442/attachment.sig>


More information about the LibreOffice mailing list