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

bug: when parsing formula in a list, panic: interface conversion: interface {} is nil, not *mathjax.mathBlockData #15

Open
pluveto opened this issue Oct 5, 2024 · 0 comments · May be fixed by #16

Comments

@pluveto
Copy link

pluveto commented Oct 5, 2024

Reproduce example:

package main

import (
	"bytes"
	"fmt"

	mathjax "github.com/litao91/goldmark-mathjax"
	"github.com/yuin/goldmark"
	"github.com/yuin/goldmark/parser"
	"github.com/yuin/goldmark/renderer/html"
)

func main() {
	md := goldmark.New(
		goldmark.WithExtensions(mathjax.MathJax),
		goldmark.WithParserOptions(
			parser.WithAutoHeadingID(),
		),
		goldmark.WithRendererOptions(
			html.WithHardWraps(),
			html.WithXHTML(),
		),
	)

	// todo more control on the parsing process
	var html bytes.Buffer
	mdContent := []byte(`

- 现在考虑整数 $n$

	$$
	n = p_1 p_2 \ldots p_k = q_1 q_2 \ldots q_l
	$$


`)
	if err := md.Convert(mdContent, &html); err != nil {
		fmt.Println(err)
	}
	fmt.Println(html.String())
}

Result:

$ go run main.go
panic: interface conversion: interface {} is nil, not *mathjax.mathBlockData

goroutine 1 [running]:
github.com/litao91/goldmark-mathjax.(*mathJaxBlockParser).Continue(0xc0002005b0?, {0x616678, 0xc000197280}, {0x615d38, 0xc0002005b0}, {0x615f38, 0xc000200690})
        /home/pluveto/go/pkg/mod/github.com/litao91/[email protected]/block.go:47 +0x3b4
github.com/yuin/goldmark/parser.(*parser).parseBlocks(0xc00020b508, {0x616ad8, 0xc000197080}, {0x615d38, 0xc0002005b0}, {0x615f38, 0xc000200690})
        /home/pluveto/go/pkg/mod/github.com/yuin/[email protected]/parser/parser.go:1063 +0x5b9
github.com/yuin/goldmark/parser.(*parser).Parse(0xc00020b508, {0x615d38, 0xc0002005b0}, {0x0, 0x0, 0x40ce45?})
        /home/pluveto/go/pkg/mod/github.com/yuin/[email protected]/parser/parser.go:848 +0x14b
github.com/yuin/goldmark.(*markdown).Convert(0xc0001f42c0, {0xc000218000, 0x53, 0x53}, {0x6149a8, 0xc00012b080}, {0x0, 0x0, 0x0})
        /home/pluveto/go/pkg/mod/github.com/yuin/[email protected]/markdown.go:116 +0xce
main.main()
        /home/pluveto/repo/blog-ws/test/main.go:37 +0x347
exit status 2
@pluveto pluveto linked a pull request Oct 5, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant