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

How to suppress number of headers and limit TOC depth? #29

Closed
michael-newsrx opened this issue Sep 12, 2023 · 2 comments
Closed

How to suppress number of headers and limit TOC depth? #29

michael-newsrx opened this issue Sep 12, 2023 · 2 comments

Comments

@michael-newsrx
Copy link

I've tried the suppress_numbering parameter to Header() but it does not seem to have any impact when I load the document up in LibreOffice. Trying to prevent numbering for depth 2 and lower and for depth 2 and lower to be excluded from TOC.

Suggestions?

@jdum
Copy link
Owner

jdum commented Sep 13, 2023

Hi, short answer: use toc.outline_level = 1 (see example below).

Long answer: Seems a bug or bad code, I dont know what is this attribute "suppress_numbering", maybe from standard version 1.0 or non-standard idea?, but certainly not in v1.2 of standard. And also missing attribute "is-list-header" that would be cool to have.

Example:

from odfdo import Document, Header, Paragraph, TOC

doc = Document("text")
body = doc.body
toc = TOC()
toc.title = "title"
body.append(toc)

body.append(Header(1, "level 1"))
body.append(Header(2, "level 2"))
body.append(Header(3, "level 3"))
body.append(Paragraph("content aaa"))
body.append(Header(3, "level 3"))
body.append(Paragraph("content aab"))
body.append(Header(2, "level 2 - B"))
body.append(Header(3, "level 3 - B1"))
body.append(Paragraph("content aba"))
body.append(Header(3, "level 3 - B2"))
body.append(Paragraph("content abb"))

toc.outline_level = 2
toc.fill()
doc.save(target="test.odt")

result like:

Table of Contents
1. level 1
1.1. level 2
1.2. level 2 - B

@michael-newsrx
Copy link
Author

Thanks!

This is a big help.

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

No branches or pull requests

2 participants