Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

А list followed by a header is parsed (or rendered?) the wrong way #283

Open
alx-ef opened this issue Jun 14, 2023 · 1 comment
Open

А list followed by a header is parsed (or rendered?) the wrong way #283

alx-ef opened this issue Jun 14, 2023 · 1 comment

Comments

@alx-ef
Copy link

alx-ef commented Jun 14, 2023

It expects an empty line between a header and a list when parsing.
This code is parsed well:

         # Header1
        * list item
        
        # Header2

this is wrong (header is interpreted as a list item):

         # Header1
        * list item        
        # Header2

But when rendering, the render doesn't put this blank line.

Thus, let say, you have AST like this:

Heading
  Text 'Header1'
List 'tight flags=start'
  ListItem 'flags=start end'
    Paragraph
      Text 'list item'
Heading
  Text 'Header2'

if you render it and parse the result, it will be different:

Heading
  Text 'Header1'
List 'flags=start'
  ListItem 'flags=has_block start'
    Paragraph
      Text 'list item'
    Heading
      Text 'Header2

Here is the test:

package md

import (
	"github.com/gomarkdown/markdown"
	"github.com/gomarkdown/markdown/md"
	"github.com/gomarkdown/markdown/parser"
	"github.com/stretchr/testify/require"
	"testing"
)

func Test_mdHeaderRendering(t *testing.T) {
	r := require.New(t)
	inMd := `# Header1
* list item

# Header2
`
	p := parser.NewWithExtensions(parser.CommonExtensions)
	doc1 := p.Parse([]byte(inMd))
	outMd := string(markdown.Render(doc1, md.NewRenderer()))

	t.Log("original MD:\n", inMd)
	t.Log("MD after serialization/deserialization:\n", outMd)

	p = parser.NewWithExtensions(parser.CommonExtensions)
	doc2 := p.Parse([]byte(outMd))
	r.Equal(len(doc1.GetChildren()), len(doc2.GetChildren()))

}

I don't know whether the renderer or the parser has a bug, but this behavior is inconsistent

@vsysoev
Copy link

vsysoev commented Jul 7, 2023

Looks like list is parsed when it starts from the new paragraph. If not, list not parsed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants