Skip to content

TextContentRenderer: ListItem renders too many spaces #413

Description

@sperol69

Steps to reproduce the problem (provide example Markdown if applicable):

List:
1. 2) 2026.
end

Expected behavior:

List:
1. 2) 2026.
end

Actual behavior: (too many spaces, increasing times after times)

List:
1.    2)       2026. 
end

(Also see what the reference implementation does: https://spec.commonmark.org/dingus/)


import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.text.LineBreakRendering;
import org.commonmark.renderer.text.TextContentRenderer;
import org.junit.jupiter.api.Test;

public class CommonMarkTest {

    String parse(String markdown) {
        Parser parser = Parser.builder() //
                .build();

        Node document = parser.parse(markdown);
        TextContentRenderer renderer = TextContentRenderer.builder() //
                .lineBreakRendering(LineBreakRendering.COMPACT) //
                .build();
        return renderer.render(document);
    }

    @Test
    void listTest_inline_ko() {
        assertAll( //
                () -> assertThat(parse("""
                        List:
                        1. 2) 2026.
                        end""")) //
                        .isEqualTo("""
                                List:
                                1. 2) 2026.
                                end"""),
                () -> assertThat(parse("""
                        List:
                        1. first
                        2. 2025. 2026. 2027.
                        end""")) //
                        .isEqualTo("""
                                List:
                                1. first
                                2. 2025. 2026. 2027.
                                end""") //
        );
    }

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions