Skip to content

Support for multilevel lists #624

Description

@Owly-dabs

Describe your problem

I can't seem to find support for multilevel lists. Does docxtpl not support this?
By "multilevel lists", I'm referring to lists as such:

  1. First text at level 1
    a. First text at level 2
    b. Second text at level 2
    i. First text at level 3
    ii. Second text at level 3
  2. Second text at level 1
    a. First text at level 2
    i. First text at level 3

More details about your problem

Initially, I tried implementing this with RichTextParagraph, with something like the following code.

def set_nested_list(self, field_name, items):
        """
        Uses custom mystyleX styles for levels 0-5
        items = [
            ("text", level),
            ("text", level),
            ...
        ]
        level determines style:
            0 -> mystyle0
            1 -> mystyle1
            2 -> mystyle2
            ...
        """
        rtp = RichTextParagraph()
        for text, level in items:
            style = f"mystyle{level}"
            rtp.add(text, parastyle=style)
        self.context[field_name] = rtp

In the jinja template, I have defined mystyle0, mystyle1, mystyle2, and so on.

However, the output looks like this (instead of above):

  1. First text at level 1
    a. First text at level 2
    b. Second text at level 2
    i. First text at level 3
    ii. Second text at level 3
  2. Second text at level 1
    c. First text at level 2
    iii. First text at level 3

As you can see, the numbering does not reset under a new style. How can I implement this?
Sorry if this issue isn't very clear, it's my first time posting one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions