Fix indent on first list item (#482) - #953
Merged
xoofx merged 3 commits intoSep 19, 2026
Merged
Conversation
boxofyellow
commented
Sep 12, 2026
Contributor
Author
There was a problem hiding this comment.
This Null check looks like it might be a copy-paste error of
https://github.com/xoofx/markdig/pull/953/changes#diff-93312f2bb29ede6862c9f8cff9baf84ba584d58bd770d388a84381e3b523af22R183
And it should instead be checking to see if lineSpecific is null. But I'm not sure since this is very much looking out for the case when lineSpecific is null
https://github.com/xoofx/markdig/pull/953/changes#diff-93312f2bb29ede6862c9f8cff9baf84ba584d58bd770d388a84381e3b523af22R109
boxofyellow
commented
Sep 12, 2026
| int index = 0; | ||
| if (listBlock.OrderedStart != null) | ||
| { | ||
| switch (listBlock.BulletType) |
Contributor
Author
There was a problem hiding this comment.
Another difference I noticed we might want to drop this limited implication of ordered lists identifiers, and instead just use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes
- > p#482 (the issues I was originally looking at)In short the
Markdig.Renderers.Normalize.ListRendererwould include the text for the "list" part of the list item as text, and then push anIndenton the stack comprised on a string of spaces, and lastly then render all the children items.This caused a problem when the first child block wanted to add its own
Indenton the stack. When that first item was a QuoteBlock,previousWasLinewithinTextRendererBasewould still be false, causing its own indent to be "eaten" on the first line of the QuoteBlock. As reported in the bugWould get changed into
At the same time if first child block was a sub list an extra new line would be inserted changing
Into
To correct this problem, I used
Markdig.Renderers.Roundtrip.ListRendereras inspiration, and updated the Normalize version to move all of the "List" data into theIndent. This did require creating a new constructor so that we could createIndents that would have a specified "first line", and all subsequent uses of theIndentwould yield a string the same width of the "first line", but made of spaces. Additional a new public method was add,PushHangingIndentto allow pushing these newIndents to the stack.This mostly addressed the problem. However it created a problem for truly empty list items. They had no children, and as a result
WriteChildrenwould effectively be a no-op. Again the Roundtrip version contains a solution, we detect this case and just write the empty string, which will respect theIndent.There is one caveat with that, as noted in the two new tests
ListUnorderedEmptyandListOrderedEmpty. With this implementation, the trailing space that follow theOrderedDelimiterorBulletTypeis always included, even if it's not in the input. We could address this within our condition for the empty list, but I was not able to find a good way to detect the case when trailing space was in the input. I assume it's better to add the space that will likely be required instead of eating it. But that can easily be changed.