Kunde21 / markdownfmt

Like gofmt, but for Markdown.
MIT License
55 stars 7 forks source link

lists: Add opt-in for indenting nested items 4 spaces #71

Closed abhinav closed 1 year ago

abhinav commented 1 year ago

We currently always indent blocks nested inside list items so that they're aligned with the list item marker.

1. foo

   bar

The Commonmark spec allows for, and some tools like pandoc prefer, to use a more uniform indentation strategy where everything is indented at least 4 spaces.

1.  foo

    bar

This change adds a new option, WithListIndentStyle which allows users to customize this behavior.

There are two styles:

Note that "uniform" does not go all the way to meet pandoc's style. Specifically, pandoc indents the initial paragraph as well:

-   foo

    bar

-   baz

For now, we're only doing nested items:

- foo

    bar

- baz

This is still valid, and it leaves more of the user's input intact. If there's a strong preference to match pandoc's style, we can switch to that in a future change.

Testing: I've added a number of new test cases extracted from list sections of other tests. To verify no change in semantics, I've also added a test that re-parses the new output and compares it with the output of the old indentation style.

Resolves #69