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

Store start on ordered lists rather than value on ordered list items #374

Merged
merged 1 commit into from May 10, 2023

Conversation

emmatown
Copy link
Contributor

@emmatown emmatown commented May 10, 2023

The way that #371 was fixed in #372 somewhat surprised me because markdown-it returns the start as an attribute on the ordered list so it can be an attribute directly on the list rather than as a new attribute on list items and adding the attribute to the list in a transform. This PR implements that approach of start as an attribute on ordered lists rather than value on ordered list items.

I've also changed the formatter to not use the number on list items so it only uses the start for the first item and 1 for all other items. For example, for this Markdoc:

2. a
7. b
20. c

The formatter in this PR outputs this:

2. a
1. b
1. c

Not preserving the numbers of the non-first items aligns with what other formatters do. For example, for the input above, Prettier outputs this:

2. a
3. b
4. c

but for this:

2. a
1. b
4. c

Prettier outputs:

2. a
1. b
1. c

Prettier's rule is "incrementing unless the number in the second list item is 1 then use 1 for everything except for the first which uses the start." Personally, I liked how Markdoc's formatter before #372 always outputted the diff-friendly style of always 1 so I've kept it like that rather than sometimes doing incrementing.

@rpaul-stripe
Copy link
Contributor

This looks good, I missed that the list open token had a start attribute. We may at some point in the future still want to capture the number used for each individual item and expose an option to have the formatter output it the way it is expressed in the source, but always using 1 is a fine default.

@rpaul-stripe rpaul-stripe merged commit dcd55c9 into markdoc:main May 10, 2023
2 checks passed
@emmatown emmatown deleted the start-on-list branch May 11, 2023 06:25
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

Successfully merging this pull request may close these issues.

None yet

3 participants