MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / is_codefence

Function is_codefence

libraries/hoedown/src/document.c:1392–1421  ·  view source on GitHub ↗

check if a line is a code fence; return the * end of the code fence. if passed, width of * the fence rule and character will be returned */

Source from the content-addressed store, hash-verified

1390 * end of the code fence. if passed, width of
1391 * the fence rule and character will be returned */
1392static size_t
1393is_codefence(uint8_t *data, size_t size, size_t *width, uint8_t *chr)
1394{
1395 size_t i = 0, n = 1;
1396 uint8_t c;
1397
1398 /* skipping initial spaces */
1399 if (size < 3)
1400 return 0;
1401
1402 if (data[0] == ' ') { i++;
1403 if (data[1] == ' ') { i++;
1404 if (data[2] == ' ') { i++; } } }
1405
1406 /* looking at the hrule uint8_t */
1407 c = data[i];
1408 if (i + 2 >= size || !(c=='~' || c=='`'))
1409 return 0;
1410
1411 /* the fence must be that same character */
1412 while (++i < size && data[i] == c)
1413 ++n;
1414
1415 if (n < 3)
1416 return 0;
1417
1418 if (width) *width = n;
1419 if (chr) *chr = c;
1420 return i;
1421}
1422
1423/* expects single line, checks if it's a codefence and extracts language */
1424static size_t

Callers 3

parse_codefenceFunction · 0.85
parse_fencedcodeFunction · 0.85
parse_listitemFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected