How to continue a numbered list after a break

is there a way to continue a list after a break ? And especially in WYSIWYG editing mode ?

what i mean is to obtain this :

TITLE
1. item
2. item
TITLE
3. item

i see this solution in css but i’m not sure how to implement it in xwiki, or even if it’s a good idea : https://stackoverflow.com/a/4615630, it implies to be able to add classes to <ol> elements.

Maybe there is an extension doing just that already ? I see this was already discussed in 2007 : [xwiki-users] numbered list

thank you all for your help :slight_smile:

Basically you want to control the number at which a list starts.

If you’re using XWiki Syntax 2.1+, you can use:

TITLE

1. item
1. item

TITLE

(% start="3" %)
1. item

Explanation: This is basically using the start parameter of the HTML OL tag, see <ol>: The Ordered List element - HTML | MDN

On the XWiki side, this is documented at https://www.xwiki.org/xwiki/bin/view/XWiki/XWikiSyntax?syntax=2.1&section=Parameters

1 Like

thank you for your answer !
unfortunately i knew that already, it’s not what i’m looking for, i want a dynamic way of doing it. That’s what i meant by WYSIWYG mode.

in the solution you propose, i need to manually change the start number every time i edit the list, but i’m wondering if there is a way to continue the list no matter how the number of items in the first part of the list change ?

Next weekend when i have time i will try to implement it myself, with the help of the xwiki documentation you sent :slight_smile:

No, there’s no way to do that automatically. Maybe you could explain what you’re trying to achieve (why you want two separate lists to be “linked”)?

Note that in WYSIWYG mode, you can right-click on a list item and open the “Numbered List Properties” to change the start number of a list. I understand it might not be what you’re looking for, but maybe it still helps.

ho, that’s a good tips :slight_smile: but indeed not what i’m looking for

my purpose is really close to my sample example :

i have a list of scientific studies, and i want them to be numbered as a whole, but in the same time i want a clear separation by dates, so i was going with this :

2025

1- study
2- study

2024

3- study

2023

4- study
5- study

and, me and other people, can come and easily add a study in a year, without having to change the start attribute of all the other years

So one easy solution I can think of is to write a custom wiki macro that generate a number by counting the previous number of itself in the XDOM.

Something like this (doesn’t work, not sure why, probably the PRECEDING is not right):

{{groovy}}
import org.xwiki.rendering.block.match.*
import org.xwiki.rendering.block.Block.*
import org.xwiki.rendering.block.*

def matcher = new MacroBlockMatcher("ol")
def currentBlock = wikimacro.context.getCurrentMacroBlock()
def blocks = currentBlock.getBlocks(matcher, Axes.PRECEDING)
println blocks.size()
{{/groovy}}

And the content would be:

= heading 1 =

* {{ol/}} Item 1
* {{ol/}} Item 2

= heading 2 =

* {{ol/}} Item 3

See also https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingMacros/WikiMacroTutorial/

PS: {{count/}} is probably a better macro name

hi, i found a solution without using macro, but by inserting css with the XWiki.StyleSheetExtension object (inspired by the css example i gave in my first question https://stackoverflow.com/a/4615630) :

ol.uninterrupted_list {
  li {
    position: relative;
    counter-increment: mycounter;
	list-style-type: none;
    padding-left: 5px;
            
    &:before {
      content: counter(mycounter) ".";
      position: absolute;
      right: 100%;
    }
            
    &:has(.separator_item) {
      position: relative;
      counter-increment: none;
      left: -45px;
      
      &:before {
        content: "";
      }
    }
  }
}

the implementation looks like this :

(% class="uninterrupted_list" start="0" %)
1. (% class="separator_item" %)title
1. item
1. item
1. (% class="separator_item" %)title
1. item
1. item
1. (% class="separator_item" %)title
1. item
1. item

and the result looks like this :

title
    1. item
    2. item
title
    3. item
    4. item
title
    5. item
    6. item

this works well, we can easily insert new items in wysiwyg, however i will look into the macros, as you suggested @vmassol, to get a better output : i would like to add functionalities to my list, like checking how much list items there is after a title and output the number :

title (3)
    1. item
    2. item
    3. item
title (1)
    4. item
title (2)
    5. item
    6. item

also i noticed an error in the css ‘compilation’ : i could not use this css : right: calc(100% + 10px); because it gets ‘compiled’ as : right: calc(100%+10px); without spaces, and neither firefox nor chrome seems to understand ‘calc’ without spaces. That’s an issue, i will open a new subject for that

Your solution has an accessibility issue. Screen readers won’t recognize your “title” as a title (which should be a heading or something like this) but will see another list item of your one(!) ordered list.

You should try to create a macro using this

== 2023 ==

1. item
1. item

== 2024 ==

(% start="XX" %)
1. item

where XX is calculated. I’m not sure if it’s possible, but that would be accessible for screen readers.

You could indeed do that with a rendering transformation. If you use a macro then it’s the solution I offered above.

shout, indeed that’s true my solution is not accessible, i’m going to try to implement @vmassol solution then :slight_smile: