mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
More work on making mkd_css() and mkd_toc() resemble each other.
This commit is contained in:
@@ -48,17 +48,22 @@ mkd_css(Document *d, char **res)
|
||||
int size;
|
||||
|
||||
if ( res && d && d->compiled ) {
|
||||
*res = 0;
|
||||
CREATE(f);
|
||||
RESERVE(f, 100);
|
||||
stylesheets(d->code, &f);
|
||||
|
||||
if ( (size = S(f)) > 0 )
|
||||
if ( (size = S(f)) > 0 ) {
|
||||
EXPAND(f) = 0;
|
||||
/* HACK ALERT! HACK ALERT! HACK ALERT! */
|
||||
*res = T(f); /* we know that a T(Cstring) is a character pointer */
|
||||
*res = T(f);/* we know that a T(Cstring) is a character pointer */
|
||||
/* so we can simply pick it up and carry it away, */
|
||||
return size; /* leaving the husk of the Ctring on the stack */
|
||||
/* leaving the husk of the Ctring on the stack */
|
||||
/* END HACK ALERT */
|
||||
}
|
||||
else
|
||||
DELETE(f);
|
||||
return size;
|
||||
}
|
||||
return EOF;
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@ mkd_toc(Document *p, char **doc)
|
||||
Cstring res;
|
||||
int size;
|
||||
|
||||
*doc = 0;
|
||||
if ( !(doc && p && p->ctx) ) return -1;
|
||||
|
||||
if ( !(p && p->ctx) ) return -1;
|
||||
*doc = 0;
|
||||
|
||||
if ( ! (p->ctx->flags & MKD_TOC) ) return 0;
|
||||
|
||||
CREATE(res);
|
||||
@@ -67,14 +68,17 @@ mkd_toc(Document *p, char **doc)
|
||||
Csprintf(&res, last_hnumber ? "%*s</ul></li>\n" : "%*s</ul>\n", last_hnumber, "");
|
||||
}
|
||||
|
||||
if ( (size = S(res)) > 0 )
|
||||
if ( (size = S(res)) > 0 ) {
|
||||
EXPAND(res) = 0;
|
||||
/* HACK ALERT! HACK ALERT! HACK ALERT! */
|
||||
*doc = T(res); /* we know that a T(Cstring) is a character pointer
|
||||
*doc = T(res); /* we know that a T(Cstring) is a character pointer
|
||||
* so we can simply pick it up and carry it away,
|
||||
* leaving the husk of the Ctring on the stack
|
||||
* END HACK ALERT
|
||||
*/
|
||||
}
|
||||
else
|
||||
DELETE(res);
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -89,9 +93,9 @@ mkd_generatetoc(Document *p, FILE *out)
|
||||
int ret = EOF;
|
||||
|
||||
if ( sz > 0 )
|
||||
ret = fwrite(buf, sz, 1, out);
|
||||
ret = fwrite(buf, 1, sz, out);
|
||||
|
||||
if ( buf ) free(buf);
|
||||
|
||||
return ret;
|
||||
return (ret == sz) ? ret : EOF;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user