mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
756 stars 138 forks source link

how to use md_parse() ? #121

Closed nkeonkeo closed 3 years ago

nkeonkeo commented 3 years ago

how to use md_parse() ?

string text="xxxxxxxxxxxx";
md_parse(text.c_str(),text.length(),NULL,NULL);

[1] 7099 segmentation fault (core dumped)

I can't understand when reading md4c.h.

What is the function of void* userdata

Can you give me a use case?

Thank you so much.

mity commented 3 years ago

See e.g. the markdown to HTML convertor: https://github.com/mity/md4c/blob/master/src/md4c-html.c#L571

mity commented 3 years ago

userdata is a pointer to any your data, you want to pass to the callbacks. You have to provide pointer to a structure in the 3rd param, which provides function pointers to your callbacks processing the parsed data.

nkeonkeo commented 3 years ago

Thank you very much! I solve the problem successfully. md4c runs very fast.