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

Panic with TOC extension #24

Open
MrZoidberg opened this issue Feb 5, 2025 · 0 comments
Open

Panic with TOC extension #24

MrZoidberg opened this issue Feb 5, 2025 · 0 comments

Comments

@MrZoidberg
Copy link

I'm using goldmark-toc extension to add a table of contents for my simple document, but the goldmark-markdown renderer panics.

Here is my markdown:

# Data API - DataAPI - Software Detailed Design

## Introduction

### Purpose


### External content


### External image

Here is my code:

import (
    markdownRndr "github.com/teekennedy/goldmark-markdown"
    "github.com/yuin/goldmark"
    "github.com/yuin/goldmark/extension"
    "github.com/yuin/goldmark/parser"
    "go.abhg.dev/goldmark/toc"
)

renderer := markdownRndr.NewRenderer()
markdown := goldmark.New(
    goldmark.WithExtensions(&toc.Extender{
        Compact:  true,
        MinDepth: 2,
        MaxDepth: 3,
    }),
    goldmark.WithParserOptions(parser.WithAutoHeadingID()),
    goldmark.WithRenderer(renderer),
)

var buf bytes.Buffer
if err := markdown.Convert([]byte(input), &buf); err != nil {
    return "", fmt.Errorf("Error rendering markdown: %v", err)
}

Error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1029f7270]

goroutine 1 [running]:
github.com/teekennedy/goldmark-markdown.(*Renderer).Render.func2({0x10315dfa8, 0x140004a0a20}, 0x1)
	/Users/mmerk/go/pkg/mod/github.com/teekennedy/goldmark-markdown@v0.4.1/renderer.go:106 +0x70
github.com/yuin/goldmark/ast.walkHelper({0x10315dfa8, 0x140004a0a20}, 0x1400069ef30)
	/Users/mmerk/go/pkg/mod/github.com/yuin/goldmark@v1.7.8/ast/ast.go:505 +0x4c
github.com/yuin/goldmark/ast.walkHelper({0x10315dd68, 0x140004a0990}, 0x1400069ef30)
	/Users/mmerk/go/pkg/mod/github.com/yuin/goldmark@v1.7.8/ast/ast.go:511 +0x1f8
github.com/yuin/goldmark/ast.walkHelper({0x10315eae8, 0x140004a0000}, 0x1400069ef30)
	/Users/mmerk/go/pkg/mod/github.com/yuin/goldmark@v1.7.8/ast/ast.go:511 +0x1f8
github.com/yuin/goldmark/ast.Walk({0x10315eae8, 0x140004a0000}, 0x1400069ef30)
	/Users/mmerk/go/pkg/mod/github.com/yuin/goldmark@v1.7.8/ast/ast.go:500 +0x3c
github.com/teekennedy/goldmark-markdown.(*Renderer).Render(0x140004a0ab0, {0x103155bc8, 0x140000ae510}, {0x140004fc1b0, 0x81, 0x90}, {0x10315eae8, 0x140004a0000})
	/Users/mmerk/go/pkg/mod/github.com/teekennedy/goldmark-markdown@v0.4.1/renderer.go:105 +0x1e0
github.com/yuin/goldmark.(*markdown).Convert(0x14000395d80, {0x140004fc1b0, 0x81, 0x90}, {0x103155bc8, 0x140000ae510}, {0x0, 0x0, 0x0})
	/Users/mmerk/go/pkg/mod/github.com/yuin/goldmark@v1.7.8/markdown.go:118 +0x100
main.(*MarkdownEngine).Render(0x1400069f960, {0x140004fc120, 0x81})
	/Users/mmerk/Code/redacted/design-doc-tool/main.go:316 +0x1d4
main.genFinalDocument({0x16da674cb, 0x30}, {0x102a95d9e, 0x18}, {0x102a9031b, 0xf}, {0x102a8f10b, 0xd}, 0x140003ad2c0, {{0x10315a160, ...}})
	/Users/mmerk/Code/redacted/design-doc-tool/main.go:177 +0xe64
main.main()
	/Users/mmerk/Code/redacted/design-doc-tool/main.go:74 +0xb24
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

1 participant