toc.c (discount-2.2.4.tar.bz2) | : | toc.c (discount-2.2.6.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
/* write an header index | /* write an header index | |||
*/ | */ | |||
int | int | |||
mkd_toc(Document *p, char **doc) | mkd_toc(Document *p, char **doc) | |||
{ | { | |||
Paragraph *tp, *srcp; | Paragraph *tp, *srcp; | |||
int last_hnumber = 0; | int last_hnumber = 0; | |||
Cstring res; | Cstring res; | |||
int size; | int size; | |||
int first = 1; | int first = 1; | |||
extern void Csreparse(Cstring *, char *, int, mkd_flag_t); | ||||
if ( !(doc && p && p->ctx) ) return -1; | if ( !(doc && p && p->ctx) ) return -1; | |||
*doc = 0; | *doc = 0; | |||
if ( ! (p->ctx->flags & MKD_TOC) ) return 0; | if ( ! is_flag_set(p->ctx->flags, MKD_TOC) ) return 0; | |||
CREATE(res); | CREATE(res); | |||
RESERVE(res, 100); | RESERVE(res, 100); | |||
for ( tp = p->code; tp ; tp = tp->next ) { | for ( tp = p->code; tp ; tp = tp->next ) { | |||
if ( tp->typ == SOURCE ) { | if ( tp->typ == SOURCE ) { | |||
for ( srcp = tp->down; srcp; srcp = srcp->next ) { | for ( srcp = tp->down; srcp; srcp = srcp->next ) { | |||
if ( (srcp->typ == HDR) && srcp->text ) { | if ( (srcp->typ == HDR) && srcp->text ) { | |||
while ( last_hnumber > srcp->hnumber ) { | while ( last_hnumber > srcp->hnumber ) { | |||
skipping to change at line 65 | skipping to change at line 66 | |||
while ( srcp->hnumber > last_hnumber ) { | while ( srcp->hnumber > last_hnumber ) { | |||
Csprintf(&res, "%*s<ul>\n", last_hnumber, ""); | Csprintf(&res, "%*s<ul>\n", last_hnumber, ""); | |||
if ( (srcp->hnumber - last_hnumber) > 1 ) | if ( (srcp->hnumber - last_hnumber) > 1 ) | |||
Csprintf(&res, "%*s<li>\n", last_hnumber+1, ""); | Csprintf(&res, "%*s<li>\n", last_hnumber+1, ""); | |||
++last_hnumber; | ++last_hnumber; | |||
} | } | |||
Csprintf(&res, "%*s<li><a href=\"#", srcp->hnumber, ""); | Csprintf(&res, "%*s<li><a href=\"#", srcp->hnumber, ""); | |||
mkd_string_to_anchor(T(srcp->text->text), | mkd_string_to_anchor(T(srcp->text->text), | |||
S(srcp->text->text), | S(srcp->text->text), | |||
(mkd_sta_function_t)Csputc, &res,1,p->ct | (mkd_sta_function_t)Csputc, | |||
x->flags); | &res,1,p->ctx); | |||
Csprintf(&res, "\">"); | Csprintf(&res, "\">"); | |||
Csreparse(&res, T(srcp->text->text), | Csreparse(&res, T(srcp->text->text), | |||
S(srcp->text->text), IS_LABEL); | S(srcp->text->text), IS_LABEL); | |||
Csprintf(&res, "</a>"); | Csprintf(&res, "</a>"); | |||
first = 0; | first = 0; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 4 lines changed or added |