Skip to content

Extra newline added in the middle of list #340

@laurelschmidt

Description

@laurelschmidt

If a list contains sub-lists, an extra newline gets added inappropriately between list items. 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## First Subsection\n\n*Content of first subsection.\n* More\n    * Yet more"
	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 (note the extra newline before "* More"):

Test string was modified during parsing and rendering. Expected:

"# Main Header\n\n## First Subsection\n\nContent of first subsection.\n More\n * Yet more"

Got:

"# Main Header\n\n## First Subsection\n\nContent of first subsection.\n\n More\n * Yet more\n\n\n"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions