Unobtrusively support the breaking up of ordered lists without resetting their indices/steps #741
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Markdown is known for resetting the counter on broken-up ordered lists, where this...
...turns into...
This behavior can be frustrating since markdown blatantly disregards the
3
the user typed and implicitly turns in into a1
. Various hacks have been suggested, but none of them are exactly satisfying.This PR fixes the issue by associating each
li
in an ordered list with an explicitdata-step
attribute that is based on the number the user typed:This change is probably backwards compatible for consumers since it is unlikely that they depend on a
data-step
attribute onli
elements already. Nor dodata
attributes change UIs in any way unless configured to do so – they are generally unobtrusive.If consumers do depend on pre-existing
data-step
attributes, it's easy to disable the data-step attribute on the producer side by simply not including it:Consumers can opt in to the new behavior with this simple CSS:
If they do not, counters will continue to break as before.
However, on the producer side, those who override the
list_item
method will need to add astep
parameter to support the new 3-arity, as shown above:Therefore, this PR introduces a breaking change – hence the new major version 7.
For unordered lists, the
step
parameter can simply be disregarded by producers (though it is still passed tolist_item
but should always be0
). It does not make it to the consumer, ie noli
elements in unordered lists ever have anydata-step
attribute.I have no experience writing C and took a bunch of educated guesses with the help of AI. Please take a close look at the proposed changes. I did add tests and they all pass for me; I've also tested the behavior on a site for which I use the gem and it seems to work fine.
If this PR isn't satisfactory, an alternative implementation to consider is to add a
start
attribute to theol
based on the first list item's number. Something like......turning into:
I see that's how GitHub does it. However, I believe this approach would make turning HTML back into markdown more difficult. In addition, the consumer-side wouldn't be backwards compatible, nor would this approach allow arbitrary, eg non-subsequent, counters.
EDIT 2023-08-26: Made some edits throughout.