# Ordered list continue numbering

**URL:** <https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720>\
**Category:** Uncategorized\
**Created:** [April 22, 2020, 5:13am UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720 "2020-04-22T05:13:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nowylie](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/nowylie/32/1440_2.png) [@nowylie](https://discuss.prosemirror.net/u/nowylie)\
**Post date:** [April 22, 2020, 5:13am UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/1 "2020-04-22T05:13:14Z")

</div>

Hi All,

I’m trying to implement a feature that allows users to “continue” the numbering of an ordered list. For example:

```auto
<ol>
  <li>One</li>
  <li>Two</li>
<ol>
<p>Inbetween</p>
<ol start="3">
  <li>Three</li>
  <li>Four</li>
</ol>

```

Would result in:

```auto
1. One
2. Two
Inbetween
3. Three
4. Four

```

Ideally, users can toggle whether a given `<ol>` should “continue” or not and the `start` attribute should be computed automatically.

Previously we had implemented the feature using CSS counters, but we are no longer able to use them so I’m looking for an alternative.

Would there be a good way to write a plugin so that I can compute the `start` attribute of a given `<ol>`?

Thanks.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [April 22, 2020, 6:37am UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/2 "2020-04-22T06:37:35Z")

</div>

If this would be an attribute on the list node type (opting in to continued numbering), you could have a plugin with an `appendTransaction` hook check for inconsistent numbering and patch it up after every transaction, I guess.

---

<div class="post-metadata">

**Author:** ![astevenson](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@astevenson](https://discuss.prosemirror.net/u/astevenson)\
**Post date:** [April 22, 2020, 2:39pm UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/3 "2020-04-22T14:39:29Z")

</div>

This how I handle both a table of contents node and footnotes and it works well, but as Marijn warned in a different thread, you’ll have to watch out for race conditions between plugins. Here’s a simplified version of our footnotes plugin if that’s helpful.

```auto
import {Plugin} from "prosemirror-state"

// Search out all Footnote nodes and make sure they're numbered correctly
let findTheFoot = (state) => {
  let counter = 0;
  let transaction = state.tr

  state.doc.descendants((node, pos) => {
    if(node.type.name !== 'apm_footnote') return true
    counter = counter + 1

    if (node.attrs.number !== counter) {
      let newAttrs = Object.assign({}, node.attrs, { number: counter } )
      transaction.setNodeMarkup(pos, null, newAttrs)
    }

    return true;
  })

  if (transaction.docChanged) return transaction
}

export function createFootNotesPlugin() {
  return new Plugin({
    appendTransaction: (transactions, oldState, newState) => {
      // bail if no change
      if (transactions.find(tr => tr.docChanged )){
        return findTheFoot(newState)
      }
    }
  })
}

```

---

<div class="post-metadata">

**Author:** ![nowylie](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/nowylie/32/1440_2.png) [@nowylie](https://discuss.prosemirror.net/u/nowylie)\
**Post date:** [April 22, 2020, 9:55pm UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/4 "2020-04-22T21:55:34Z")

</div>

Thanks! This looks like it could solve my problem.

@marijn can you comment on the “race conditions”? I wouldn’t normally expect to deal with race conditions in a JS library. Is there something I need to be aware of/look out for?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [April 23, 2020, 7:18am UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/5 "2020-04-23T07:18:06Z")

</div>

> [@nowylie](#):
>
> @marijn can you comment on the “race conditions”? I wouldn’t normally expect to deal with race conditions in a JS library. Is there something I need to be aware of/look out for?

I think what was meant is infinite loops where two plugins keep reacting to each other’s appended transactions by appending more transactions.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [April 23, 2020, 7:19am UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/6 "2020-04-23T07:19:47Z")

</div>

> [@nowylie](#):
>
> @marijn can you comment on the “race conditions”? I wouldn’t normally expect to deal with race conditions in a JS library. Is there something I need to be aware of/look out for?

I think what was meant is infinite loops where two plugins keep reacting to each other’s appended transactions by appending more transactions.

---

<div class="post-metadata">

**Author:** ![astevenson](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@astevenson](https://discuss.prosemirror.net/u/astevenson)\
**Post date:** [April 23, 2020, 4:18pm UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/7 "2020-04-23T16:18:41Z")

</div>

> [@marijn](#):
>
> I think what was meant is infinite loops where two plugins keep reacting to each other’s appended transactions by appending more transactions.

Yep, my bad.

---

<div class="post-metadata">

**Author:** ![nowylie](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/nowylie/32/1440_2.png) [@nowylie](https://discuss.prosemirror.net/u/nowylie)\
**Post date:** [April 23, 2020, 9:35pm UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/8 "2020-04-23T21:35:51Z")

</div>

Fair enough!

What would be best practice to try and prevent this? I only really need to run the plugin code when a new `<li>` is created or when an `<ol>` is toggled, and the code only needs to affect sibling lists (it doesn’t need to traverse the document tree).

Is it reasonable to inspect the `transactions` to try and determine what changes were made?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [April 24, 2020, 6:35am UTC](https://discuss.prosemirror.net/t/ordered-list-continue-numbering/2720/9 "2020-04-24T06:35:17Z")

</div>

> [@nowylie](#):
>
> Is it reasonable to inspect the `transactions` to try and determine what changes were made?

Yes, that’s exactly how to do this.
