static void md_convert_hashes(cmark_iter *const iter) { for(;;) { cmark_event_type const event = cmark_iter_next(iter); if(CMARK_EVENT_DONE == event) break; if(CMARK_EVENT_EXIT != event) continue; cmark_node *const node = cmark_iter_get_node(iter); cmark_node_type const type = cmark_node_get_type(node); if(CMARK_NODE_LINK != type && CMARK_NODE_IMAGE != type) continue; char const *const URI = cmark_node_get_url(node); if(!URI) continue; if(0 != strncasecmp(URI, STR_LEN("hash:"))) continue; cmark_node *sup = superscript("#", HASH_INFO_MSG, URI); cmark_node_insert_after(node, sup); cmark_iter_reset(iter, sup, CMARK_EVENT_EXIT); char *escaped = QSEscape(URI, strlen(URI), true); size_t const elen = strlen(escaped); cmark_strbuf rel[1]; char const qpfx[] = "/sources/"; cmark_strbuf_init(&DEFAULT_MEM_ALLOCATOR, rel, sizeof(qpfx)-1+elen); cmark_strbuf_put(rel, (unsigned char const *)qpfx, sizeof(qpfx)-1); cmark_strbuf_put(rel, (unsigned char const *)escaped, elen); free(escaped); escaped = NULL; cmark_node_set_url(node, cmark_strbuf_cstr(rel)); cmark_strbuf_free(rel); } }
const char* cmark_node_get_fence_info(cmark_node *node) { if (node->type == NODE_FENCED_CODE) { return cmark_strbuf_cstr(&node->as.code.info); } else { return NULL; } }
const char* cmark_node_get_string_content(cmark_node *node) { switch (node->type) { case NODE_INDENTED_CODE: case NODE_FENCED_CODE: case NODE_HTML: return cmark_strbuf_cstr(&node->string_content); case NODE_STRING: case NODE_INLINE_HTML: case NODE_INLINE_CODE: return cmark_chunk_to_cstr(&node->as.literal); default: break; } return NULL; }