ext/markdown.c in rdiscount-1.5.5 vs ext/markdown.c in rdiscount-1.5.8

- old
+ new

@@ -228,10 +228,12 @@ if ( depth == 0 ) { while ( c != EOF && c != '>' ) { /* consume trailing gunk in close tag */ c = flogetc(&f); } + if ( !f.t ) + return 0; ret = f.t->next; f.t->next = 0; return ret; } } @@ -267,21 +269,28 @@ static int istable(Line *t) { char *p; Line *dashes = t->next; + int contains = 0; /* found character bits; 0x01 is |, 0x02 is - */ /* two lines, first must contain | */ if ( !(dashes && memchr(T(t->text), '|', S(t->text))) ) return 0; - /* second line must be only whitespace, |, -, or - */ + /* second line must contain - or | and nothing + * else except for whitespace or : + */ for ( p = T(dashes->text)+S(dashes->text)-1; p >= T(dashes->text); --p) - if ( ! ((*p == '|') || (*p == ':') || (*p == '-') || isspace(*p)) ) + if ( *p == '|' ) + contains |= 0x01; + else if ( *p == '-' ) + contains |= 0x02; + else if ( ! ((*p == ':') || isspace(*p)) ) return 0; - return 1; + return (contains & 0x03); } /* footnotes look like ^<whitespace>{0,3}[stuff]: <content>$ */ @@ -377,10 +386,14 @@ if ( t->next ) { char *q = T(t->next->text); if ( (*q == '=') || (*q == '-') ) { - for (i=1; i < S(t->next->text); i++) + /* find trailing space on === line */ + int e = S(t->next->text) - 1; + while (e > 1 && q[e] == ' ') e--; + + for (i=1; i <= e; i++) if ( q[0] != q[i] ) return 0; *htyp = SETEXT; return 1; }