A block string value (`|md ...|`, `||...||`, `|||...|||`, |`...`|): its * text, read on through the lines it spans, and what follows its closing * delimiter on that line. False when value opens none. */
| 1955 | * text, read on through the lines it spans, and what follows its closing |
| 1956 | * delimiter on that line. False when value opens none. */ |
| 1957 | static bool d2_block(dg_lines_t *it, dg_str_t value, dg_str_t *text, dg_str_t *after) { |
| 1958 | size_t pipes = 0; |
| 1959 | while (pipes < value.n && value.p[pipes] == '|') { |
| 1960 | pipes++; |
| 1961 | } |
| 1962 | if (pipes == 0 || pipes + PAIR_LEN > D2_DELIM_MAX) { |
| 1963 | return false; |
| 1964 | } |
| 1965 | char close[D2_DELIM_MAX]; |
| 1966 | size_t cl = 0; |
| 1967 | size_t open = pipes; |
| 1968 | if (open < value.n && value.p[open] == '`') { |
| 1969 | close[cl++] = '`'; |
| 1970 | open++; |
| 1971 | } |
| 1972 | for (size_t i = 0; i < pipes; i++) { |
| 1973 | close[cl++] = '|'; |
| 1974 | } |
| 1975 | while (open < value.n && !isspace((unsigned char)value.p[open])) { /* the language tag */ |
| 1976 | open++; |
| 1977 | } |
| 1978 | const char *from = value.p + open; |
| 1979 | const char *at = NULL; |
| 1980 | for (const char *q = from; q + cl <= it->end && !at; q++) { |
| 1981 | at = memcmp(q, close, cl) == 0 ? q : NULL; |
| 1982 | } |
| 1983 | at = at ? at : it->end; |
| 1984 | *text = dg_s(from, (size_t)(at - from)); |
| 1985 | const char *rest = at + (at < it->end ? cl : 0); |
| 1986 | const char *eol = memchr(rest, '\n', (size_t)(it->end - rest)); |
| 1987 | eol = eol ? eol : it->end; |
| 1988 | *after = dg_trim(dg_s(rest, (size_t)(eol - rest))); |
| 1989 | dg_str_t skipped; |
| 1990 | uint32_t l = 0; |
| 1991 | while (it->p <= at && dg_next_line(it, &skipped, &l)) { /* the lines the block spans */ |
| 1992 | } |
| 1993 | return true; |
| 1994 | } |
| 1995 | |
| 1996 | /* A block string's label: its first line of text, tags and heading marks |
| 1997 | * dropped. */ |
no test coverage detected