Skip to content

Extra newlines after sub-lists #339

@laurelschmidt

Description

@laurelschmidt

It looks like 2 newlines are added after a list, if the list has only one level (this is expected behavior), but three newlines are added after a list if the last element of the list is a sub-bullet/indented. I would expect to have only two newlines following a list, regardless of whether the last element of the list is indented.

Code to reproduce:

package main

import (
	"fmt"

	"github.com/gomarkdown/markdown"
	"github.com/gomarkdown/markdown/md"
	"github.com/gomarkdown/markdown/parser"
)

func testGomarkdown(input []byte) []byte {
	extensions := parser.NoIntraEmphasis | parser.Tables | parser.FencedCode | parser.Strikethrough | parser.SpaceHeadings | parser.HeadingIDs | parser.DefinitionLists | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
	p := parser.NewWithExtensions(extensions)
	tree := p.Parse(input)

	renderer := md.NewRenderer()
	return markdown.Render(tree, renderer)
}

func main() {
	testStr := "# Main Header\n\n## New Subsection\n\n* Another list\n    * With multiple levels\n\n## First Subsection\n\n* Content of first subsection.\n* More\n    * Yet more\n\n"
	output := testGomarkdown([]byte(testStr))
	if string(output) != testStr {
		fmt.Printf("Test string was modified during parsing and rendering. Expected:\n\n%q\n\nGot:\n\n%q", testStr, string(output))
	} else {
		fmt.Println("Test string is return unmodified.")
	}
}

Output:

Test string was modified during parsing and rendering. Expected:

"# Main Header\n\n## New Subsection\n\n* Another list\n * With multiple levels\n\n## First Subsection\n\n* Content of first subsection.\n* More\n * Yet more\n\n"

Got:

"# Main Header\n\n## New Subsection\n\n* Another list\n * With multiple levels\n\n\n## First Subsection\n\n* Content of first subsection.\n* More\n * Yet more\n\n\n"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions