static int isdivmarker(Line *p, int start, DWORD flags) { char *s; int last, i; if ( flags & (MKD_NODIVQUOTE|MKD_STRICT) ) return 0; start = nextnonblank(p, start); last= S(p->text) - (1 + start); s = T(p->text) + start; if ( (last <= 0) || (*s != '%') || (s[last] != '%') ) return 0; i = szmarkerclass(s+1); if ( !iscsschar(s[i+1]) ) return 0; while ( ++i < last ) if ( !(isdigit(s[i]) || iscsschar(s[i])) ) return 0; return 1; }
static int islist(Line *t, int *clip, DWORD flags, int *list_type) { int i, j; char *q; if ( end_of_block(t) ) return 0; if ( !(flags & (MKD_NODLIST|MKD_STRICT)) && isdefinition(t,clip,list_type) ) return DL; if ( strchr("*-+", T(t->text)[t->dle]) && isspace(T(t->text)[t->dle+1]) ) { i = nextnonblank(t, t->dle+1); *clip = (i > 4) ? 4 : i; *list_type = UL; return AL; } if ( (j = nextblank(t,t->dle)) > t->dle ) { if ( T(t->text)[j-1] == '.' ) { if ( !(flags & (MKD_NOALPHALIST|MKD_STRICT)) && (j == t->dle + 2) && isalpha(T(t->text)[t->dle]) ) { j = nextnonblank(t,j); *clip = (j > 4) ? 4 : j; *list_type = AL; return AL; } strtoul(T(t->text)+t->dle, &q, 10); if ( (q > T(t->text)+t->dle) && (q == T(t->text) + (j-1)) ) { j = nextnonblank(t,j); /* *clip = j; */ *clip = (j > 4) ? 4 : j; *list_type = OL; return AL; } } } return 0; }
struct token *gettok() { struct token *tok = malloc(sizeof(struct token)); tok->pos = malloc(sizeof(struct pos)); char c = nextnonblank(); tok->pos->line = curline; tok->pos->charstart = curchar; if (c != '\n') ungetc(c, fin); if (isdigit(c)) getnum(tok); else if (isalnum(c)) getalnum(tok); else if (c == '\'') { getc(fin); c = getc(fin); tok->type = CHAR; tok->val = malloc(3); tok->val[0] = tok->val[2] = '\''; tok->val[1] = c; c = getc(fin); if (c != '\'') { tok->pos->len = 2; error(*tok->pos, "missing ' to end character"); } } else if (c == '\"') getstring(tok); else if (c == EOF) { tok->type = ENDOFFILE; tok->val = "EOF"; } else if (c == '\n') { tok->type = EOL; tok->val = "EOL"; } else getop(tok); tok->pos->len = curchar - tok->pos->charstart; return tok; }
/* find the first nonblank character on the Line. */ int mkd_firstnonblank(Line *p) { return nextnonblank(p,0); }
/* * add a new (image or link) footnote to the footnote table */ static Line* addfootnote(Line *p, MMIOT* f) { int j, i; int c; Line *np = p->next; Footnote *foot = &EXPAND(f->footnotes->note); CREATE(foot->tag); CREATE(foot->link); CREATE(foot->title); foot->flags = foot->height = foot->width = 0; for (j=i=p->dle+1; T(p->text)[j] != ']'; j++) EXPAND(foot->tag) = T(p->text)[j]; EXPAND(foot->tag) = 0; S(foot->tag)--; j = nextnonblank(p, j+2); if ( (f->flags & MKD_EXTRA_FOOTNOTE) && (T(foot->tag)[0] == '^') ) { /* need to consume all lines until non-indented block? */ while ( j < S(p->text) ) EXPAND(foot->title) = T(p->text)[j++]; goto skip_to_end; } while ( (j < S(p->text)) && !isspace(T(p->text)[j]) ) EXPAND(foot->link) = T(p->text)[j++]; EXPAND(foot->link) = 0; S(foot->link)--; j = nextnonblank(p,j); if ( T(p->text)[j] == '=' ) { sscanf(T(p->text)+j, "=%dx%d", &foot->width, &foot->height); while ( (j < S(p->text)) && !isspace(T(p->text)[j]) ) ++j; j = nextnonblank(p,j); } if ( (j >= S(p->text)) && np && np->dle && tgood(T(np->text)[np->dle]) ) { ___mkd_freeLine(p); p = np; np = p->next; j = p->dle; } if ( (c = tgood(T(p->text)[j])) ) { /* Try to take the rest of the line as a comment; read to * EOL, then shrink the string back to before the final * quote. */ ++j; /* skip leading quote */ while ( j < S(p->text) ) EXPAND(foot->title) = T(p->text)[j++]; while ( S(foot->title) && T(foot->title)[S(foot->title)-1] != c ) --S(foot->title); if ( S(foot->title) ) /* skip trailing quote */ --S(foot->title); EXPAND(foot->title) = 0; --S(foot->title); } skip_to_end: ___mkd_freeLine(p); return np; }