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

Function parse_math

libraries/hoedown/src/document.c:718–757  ·  view source on GitHub ↗

parse_math • parses a math span until the given ending delimiter */

Source from the content-addressed store, hash-verified

716
717/* parse_math • parses a math span until the given ending delimiter */
718static size_t
719parse_math(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size, const char *end, size_t delimsz, int displaymode)
720{
721 hoedown_buffer text = { NULL, 0, 0, 0, NULL, NULL, NULL };
722 size_t i = delimsz;
723
724 if (!doc->md.math)
725 return 0;
726
727 /* find ending delimiter */
728 while (1) {
729 while (i < size && data[i] != (uint8_t)end[0])
730 i++;
731
732 if (i >= size)
733 return 0;
734
735 if (!is_escaped(data, i) && !(i + delimsz > size)
736 && memcmp(data + i, end, delimsz) == 0)
737 break;
738
739 i++;
740 }
741
742 /* prepare buffers */
743 text.data = data + delimsz;
744 text.size = i - delimsz;
745
746 /* if this is a $$ and MATH_EXPLICIT is not active,
747 * guess whether displaymode should be enabled from the context */
748 i += delimsz;
749 if (delimsz == 2 && !(doc->ext_flags & HOEDOWN_EXT_MATH_EXPLICIT))
750 displaymode = is_empty_all(data - offset, offset) && is_empty_all(data + i, size - i);
751
752 /* call callback */
753 if (doc->md.math(ob, &text, displaymode, &doc->data))
754 return i;
755
756 return 0;
757}
758
759/* char_emphasis • single and double emphasis parsing */
760static size_t

Callers 2

char_escapeFunction · 0.85
char_mathFunction · 0.85

Calls 2

is_escapedFunction · 0.85
is_empty_allFunction · 0.85

Tested by

no test coverage detected