MCPcopy Create free account
hub / github.com/commonmark/cmark / parse_inline

Function parse_inline

src/inlines.c:1332–1406  ·  view source on GitHub ↗

Parse an inline, advancing subject, and add it as a child of parent. Return 0 if no inline can be parsed, 1 otherwise.

Source from the content-addressed store, hash-verified

1330// Parse an inline, advancing subject, and add it as a child of parent.
1331// Return 0 if no inline can be parsed, 1 otherwise.
1332static int parse_inline(subject *subj, cmark_node *parent, int options) {
1333 cmark_node *new_inl = NULL;
1334 cmark_chunk contents;
1335 unsigned char c;
1336 bufsize_t startpos, endpos;
1337 c = peek_char(subj);
1338 if (c == 0) {
1339 return 0;
1340 }
1341 switch (c) {
1342 case '\r':
1343 case '\n':
1344 new_inl = handle_newline(subj);
1345 break;
1346 case '`':
1347 new_inl = handle_backticks(subj, options);
1348 break;
1349 case '\\':
1350 new_inl = handle_backslash(subj);
1351 break;
1352 case '&':
1353 new_inl = handle_entity(subj);
1354 break;
1355 case '<':
1356 new_inl = handle_pointy_brace(subj, options);
1357 break;
1358 case '*':
1359 case '_':
1360 case '\'':
1361 case '"':
1362 new_inl = handle_delim(subj, c, (options & CMARK_OPT_SMART) != 0);
1363 break;
1364 case '-':
1365 new_inl = handle_hyphen(subj, (options & CMARK_OPT_SMART) != 0);
1366 break;
1367 case '.':
1368 new_inl = handle_period(subj, (options & CMARK_OPT_SMART) != 0);
1369 break;
1370 case '[':
1371 advance(subj);
1372 new_inl = make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("["));
1373 push_bracket(subj, false, new_inl);
1374 break;
1375 case ']':
1376 new_inl = handle_close_bracket(subj);
1377 break;
1378 case '!':
1379 advance(subj);
1380 if (peek_char(subj) == '[') {
1381 advance(subj);
1382 new_inl = make_str(subj, subj->pos - 2, subj->pos - 1, cmark_chunk_literal("!["));
1383 push_bracket(subj, true, new_inl);
1384 } else {
1385 new_inl = make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("!"));
1386 }
1387 break;
1388 default:
1389 endpos = subject_find_special_char(subj, options);

Callers 1

cmark_parse_inlinesFunction · 0.85

Calls 15

peek_charFunction · 0.85
handle_newlineFunction · 0.85
handle_backticksFunction · 0.85
handle_backslashFunction · 0.85
handle_entityFunction · 0.85
handle_pointy_braceFunction · 0.85
handle_delimFunction · 0.85
handle_hyphenFunction · 0.85
handle_periodFunction · 0.85
make_strFunction · 0.85
cmark_chunk_literalFunction · 0.85
push_bracketFunction · 0.85

Tested by

no test coverage detected