github / cmark-gfm

GitHub's fork of cmark, a CommonMark parsing and rendering library and program in C
Other
871 stars 171 forks source link

No type string for `CMARK_NODE_FOOTNOTE_REFERENCE`, `CMARK_NODE_FOOTNOTE_DEFINITION` #341

Open matthewhughes934 opened 12 months ago

matthewhughes934 commented 12 months ago

Nodes of this type return "<unknown>" when passed to cmark_node_get_type_string is it intentional that there's no entry for these types in that function?

Basic program to show the "<unknown>"s:

#include <stdio.h>
#include <string.h>
#include "cmark-gfm.h"

int main(void)
{
  const char *document = "Here's a footnote[^1]\n\n[^1]: a reference\n";
  cmark_node *root = cmark_parse_document(document, strlen(document), CMARK_OPT_DEFAULT | CMARK_OPT_FOOTNOTES);
  cmark_iter *iter = cmark_iter_new(root);

  for (cmark_event_type ev_type = cmark_iter_next(iter); ev_type != CMARK_EVENT_DONE; ev_type = cmark_iter_next(iter)) {
    if (ev_type == CMARK_EVENT_ENTER) {
      cmark_node *cur = cmark_iter_get_node(iter);
      printf("%s\n", cmark_node_get_type_string(cur));
    }
  }

  cmark_iter_free(iter);
  cmark_node_free(root);

  return 0;
}

Output:

document
paragraph
text
<unknown>
<unknown>
paragraph
text
matthewhughes934 commented 12 months ago

I think this is also related to #316 since for a footnote the XML tag is just generated via cmark_node_get_type_for_string https://github.com/github/cmark-gfm/blob/f94b7ed311688b4e14ed10904af98d4536414267/src/xml.c#L151

zkamvar commented 2 months ago

I've attempted to address this in #362, but I'm still waiting on response from the GitHub maintainers.