Extract XML element name from start_tag/self_closing_tag children.
| 7066 | |
| 7067 | // Extract XML element name from start_tag/self_closing_tag children. |
| 7068 | static char *find_xml_element_name(CBMArena *a, TSNode node, const char *source) { |
| 7069 | uint32_t nc = ts_node_child_count(node); |
| 7070 | for (uint32_t i = 0; i < nc; i++) { |
| 7071 | TSNode child = ts_node_child(node, i); |
| 7072 | const char *ck = ts_node_type(child); |
| 7073 | if (strcmp(ck, "start_tag") == 0 || strcmp(ck, "self_closing_tag") == 0 || |
| 7074 | strcmp(ck, "STag") == 0 || strcmp(ck, "EmptyElemTag") == 0) { |
| 7075 | uint32_t tnc = ts_node_child_count(child); |
| 7076 | for (uint32_t j = 0; j < tnc; j++) { |
| 7077 | TSNode tag = ts_node_child(child, j); |
| 7078 | const char *tk = ts_node_type(tag); |
| 7079 | if (strcmp(tk, "tag_name") == 0 || strcmp(tk, "Name") == 0) { |
| 7080 | return cbm_node_text(a, tag, source); |
| 7081 | } |
| 7082 | } |
| 7083 | } |
| 7084 | } |
| 7085 | // Fallback: try "Name" field directly for some XML grammars |
| 7086 | TSNode name_child = cbm_find_child_by_kind(node, "Name"); |
| 7087 | if (!ts_node_is_null(name_child)) { |
| 7088 | return cbm_node_text(a, name_child, source); |
| 7089 | } |
| 7090 | return NULL; |
| 7091 | } |
| 7092 | |
| 7093 | // Extract text from an atx_heading node (# Title). |
| 7094 | static char *extract_atx_heading_text(CBMArena *a, TSNode node, const char *source) { |
no test coverage detected