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

[StackOverflow] Creating a new Visitor leads to wrapping value error #218

Closed
tanishqkancharla opened this issue Jun 14, 2020 · 1 comment

Comments

@tanishqkancharla
Copy link

tanishqkancharla commented Jun 14, 2020

Hello! I love this project! For my purposes, I've been making a Visitor that renders markdown text to SwiftUI Views. However, accessing any data of a node leads to the following error:

Fatal error: Couldn't wrap node of type: cmark_node_type(rawValue: 0): file .../BaseNode.swift, line 23

The code breaks on the line I print node.children in rendering a heading node in my visitor class (but the same error occurs on other nodes as well):

func visit(heading node: Heading) -> Result {
        print("Heading node \(node)")
        print("Children are \(node.children)")
        print("Depth is \(node.nestDepth)")
        
        return AnyView(EmptyView())
    }

This is where I initiate the AST traversal:

//       text is equal to "### First block"
        let node = try Down(markdownString: text).toAST().wrap() as! Document
//        let st = node.accept(AttributedStringVisitor(styler: DownStyler()))
//        print(String(reflecting: st))
        return node.accept(Viewer())

The confusing part is, this error only happens occasionally, and if I uncomment the code above that uses the default styler traversal, the code always runs fine, which makes me think it has to do with a problem with the lazy variables I'm using. Does anyone have any insight on this?

@iwasrobbed-ks
Copy link
Collaborator

Hi there 👋 Please consider asking general questions about working with cmark and Down on StackOverflow.com rather than here. The only issues that should be filed on this GitHub repo is if it's a bug in Down that needs addressing. Thanks!

@iwasrobbed-ks iwasrobbed-ks changed the title Creating a new Visitor leads to wrapping value error [StackOverflow] Creating a new Visitor leads to wrapping value error Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants