char_link • '[': parsing a link, a footnote or an image */
| 1066 | |
| 1067 | /* char_link • '[': parsing a link, a footnote or an image */ |
| 1068 | static size_t |
| 1069 | char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size) |
| 1070 | { |
| 1071 | int is_img = (offset && data[-1] == '!' && !is_escaped(data - offset, offset - 1)); |
| 1072 | int is_footnote = (doc->ext_flags & HOEDOWN_EXT_FOOTNOTES && data[1] == '^'); |
| 1073 | size_t i = 1, txt_e, link_b = 0, link_e = 0, title_b = 0, title_e = 0; |
| 1074 | hoedown_buffer *content = NULL; |
| 1075 | hoedown_buffer *link = NULL; |
| 1076 | hoedown_buffer *title = NULL; |
| 1077 | hoedown_buffer *u_link = NULL; |
| 1078 | size_t org_work_size = doc->work_bufs[BUFFER_SPAN].size; |
| 1079 | int ret = 0, in_title = 0, qtype = 0; |
| 1080 | |
| 1081 | /* checking whether the correct renderer exists */ |
| 1082 | if ((is_footnote && !doc->md.footnote_ref) || (is_img && !doc->md.image) |
| 1083 | || (!is_img && !is_footnote && !doc->md.link)) |
| 1084 | goto cleanup; |
| 1085 | |
| 1086 | /* looking for the matching closing bracket */ |
| 1087 | i += find_emph_char(data + i, size - i, ']'); |
| 1088 | txt_e = i; |
| 1089 | |
| 1090 | if (i < size && data[i] == ']') i++; |
| 1091 | else goto cleanup; |
| 1092 | |
| 1093 | /* footnote link */ |
| 1094 | if (is_footnote) { |
| 1095 | hoedown_buffer id = { NULL, 0, 0, 0, NULL, NULL, NULL }; |
| 1096 | struct footnote_ref *fr; |
| 1097 | |
| 1098 | if (txt_e < 3) |
| 1099 | goto cleanup; |
| 1100 | |
| 1101 | id.data = data + 2; |
| 1102 | id.size = txt_e - 2; |
| 1103 | |
| 1104 | fr = find_footnote_ref(&doc->footnotes_found, id.data, id.size); |
| 1105 | |
| 1106 | /* mark footnote used */ |
| 1107 | if (fr && !fr->is_used) { |
| 1108 | if(!add_footnote_ref(&doc->footnotes_used, fr)) |
| 1109 | goto cleanup; |
| 1110 | fr->is_used = 1; |
| 1111 | fr->num = doc->footnotes_used.count; |
| 1112 | |
| 1113 | /* render */ |
| 1114 | if (doc->md.footnote_ref) |
| 1115 | ret = doc->md.footnote_ref(ob, fr->num, &doc->data); |
| 1116 | } |
| 1117 | |
| 1118 | goto cleanup; |
| 1119 | } |
| 1120 | |
| 1121 | /* skip any amount of spacing */ |
| 1122 | /* (this is much more laxist than original markdown syntax) */ |
| 1123 | while (i < size && _isspace(data[i])) |
| 1124 | i++; |
| 1125 |
nothing calls this directly
no test coverage detected