Fossil SCM
Improvements to automatic end-tags.
Commit
a7807a8b9c440d37a985e60a11de69abac9ac7029fe8553d3b2b658a827a9f2a
Parent
bc2e6fbeb5f3c3c…
1 file changed
+7
-4
+7
-4
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -249,10 +249,13 @@ | ||
| 249 | 249 | #define MUTYPE_TR 0x0080 /* <tr> */ |
| 250 | 250 | #define MUTYPE_TD 0x0100 /* <td> or <th> */ |
| 251 | 251 | #define MUTYPE_SPECIAL 0x0200 /* <nowiki> or <verbatim> */ |
| 252 | 252 | #define MUTYPE_HYPERLINK 0x0400 /* <a> */ |
| 253 | 253 | |
| 254 | +/* MUTYPE values for elements that require strictly nested end-tags */ | |
| 255 | +#define MUTYPE_Nested 0x0656 | |
| 256 | + | |
| 254 | 257 | /* |
| 255 | 258 | ** These markup types must have an end tag. |
| 256 | 259 | */ |
| 257 | 260 | #define MUTYPE_STACK (MUTYPE_BLOCK | MUTYPE_FONT | MUTYPE_LIST | MUTYPE_TABLE) |
| 258 | 261 | |
| @@ -2423,10 +2426,11 @@ | ||
| 2423 | 2426 | |
| 2424 | 2427 | /* |
| 2425 | 2428 | ** Push a new element onto the tag statk |
| 2426 | 2429 | */ |
| 2427 | 2430 | void html_tagstack_push(HtmlTagStack *p, int e){ |
| 2431 | + if( (aMarkup[e].iType & MUTYPE_Nested)==0 ) return; | |
| 2428 | 2432 | if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){ |
| 2429 | 2433 | if( p->nAlloc==0 ){ |
| 2430 | 2434 | int *aNew; |
| 2431 | 2435 | p->nAlloc = 50; |
| 2432 | 2436 | aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc ); |
| @@ -2462,19 +2466,20 @@ | ||
| 2462 | 2466 | ** If there is no open-tag for eEnd on the stack, then this |
| 2463 | 2467 | ** routine is a no-op. |
| 2464 | 2468 | */ |
| 2465 | 2469 | void html_tagstack_pop(HtmlTagStack *p, Blob *pBlob, int eEnd){ |
| 2466 | 2470 | int i; |
| 2471 | + if( (aMarkup[eEnd].iType & MUTYPE_Nested)==0 ) return; | |
| 2467 | 2472 | for(i=p->n-1; i>=0 && p->aStack[i]!=eEnd; i--){} |
| 2468 | 2473 | if( i<0 ){ |
| 2469 | 2474 | blob_appendf(pBlob, "<span class='error'></%s></span>", |
| 2470 | 2475 | aMarkup[eEnd].zName); |
| 2471 | 2476 | return; |
| 2472 | 2477 | } |
| 2473 | 2478 | do{ |
| 2474 | 2479 | p->n--; |
| 2475 | - blob_appendf(pBlob, "</%s>", aMarkup[eEnd].zName); | |
| 2480 | + blob_appendf(pBlob, "</%s>", aMarkup[p->aStack[p->n]].zName); | |
| 2476 | 2481 | }while( p->aStack[p->n]!=eEnd ); |
| 2477 | 2482 | } |
| 2478 | 2483 | |
| 2479 | 2484 | /* |
| 2480 | 2485 | ** Append HTML text to a Blob object. The appended text is modified |
| @@ -2533,13 +2538,11 @@ | ||
| 2533 | 2538 | }else{ |
| 2534 | 2539 | if( markup.endTag ){ |
| 2535 | 2540 | html_tagstack_pop(&s, pBlob, markup.iCode); |
| 2536 | 2541 | }else{ |
| 2537 | 2542 | renderMarkup(pBlob, &markup); |
| 2538 | - if( markup.iType!=MUTYPE_SINGLE ){ | |
| 2539 | - html_tagstack_push(&s, markup.iCode); | |
| 2540 | - } | |
| 2543 | + html_tagstack_push(&s, markup.iCode); | |
| 2541 | 2544 | } |
| 2542 | 2545 | } |
| 2543 | 2546 | unparseMarkup(&markup); |
| 2544 | 2547 | } |
| 2545 | 2548 | while( s.n>0 ){ |
| 2546 | 2549 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -249,10 +249,13 @@ | |
| 249 | #define MUTYPE_TR 0x0080 /* <tr> */ |
| 250 | #define MUTYPE_TD 0x0100 /* <td> or <th> */ |
| 251 | #define MUTYPE_SPECIAL 0x0200 /* <nowiki> or <verbatim> */ |
| 252 | #define MUTYPE_HYPERLINK 0x0400 /* <a> */ |
| 253 | |
| 254 | /* |
| 255 | ** These markup types must have an end tag. |
| 256 | */ |
| 257 | #define MUTYPE_STACK (MUTYPE_BLOCK | MUTYPE_FONT | MUTYPE_LIST | MUTYPE_TABLE) |
| 258 | |
| @@ -2423,10 +2426,11 @@ | |
| 2423 | |
| 2424 | /* |
| 2425 | ** Push a new element onto the tag statk |
| 2426 | */ |
| 2427 | void html_tagstack_push(HtmlTagStack *p, int e){ |
| 2428 | if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){ |
| 2429 | if( p->nAlloc==0 ){ |
| 2430 | int *aNew; |
| 2431 | p->nAlloc = 50; |
| 2432 | aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc ); |
| @@ -2462,19 +2466,20 @@ | |
| 2462 | ** If there is no open-tag for eEnd on the stack, then this |
| 2463 | ** routine is a no-op. |
| 2464 | */ |
| 2465 | void html_tagstack_pop(HtmlTagStack *p, Blob *pBlob, int eEnd){ |
| 2466 | int i; |
| 2467 | for(i=p->n-1; i>=0 && p->aStack[i]!=eEnd; i--){} |
| 2468 | if( i<0 ){ |
| 2469 | blob_appendf(pBlob, "<span class='error'></%s></span>", |
| 2470 | aMarkup[eEnd].zName); |
| 2471 | return; |
| 2472 | } |
| 2473 | do{ |
| 2474 | p->n--; |
| 2475 | blob_appendf(pBlob, "</%s>", aMarkup[eEnd].zName); |
| 2476 | }while( p->aStack[p->n]!=eEnd ); |
| 2477 | } |
| 2478 | |
| 2479 | /* |
| 2480 | ** Append HTML text to a Blob object. The appended text is modified |
| @@ -2533,13 +2538,11 @@ | |
| 2533 | }else{ |
| 2534 | if( markup.endTag ){ |
| 2535 | html_tagstack_pop(&s, pBlob, markup.iCode); |
| 2536 | }else{ |
| 2537 | renderMarkup(pBlob, &markup); |
| 2538 | if( markup.iType!=MUTYPE_SINGLE ){ |
| 2539 | html_tagstack_push(&s, markup.iCode); |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | unparseMarkup(&markup); |
| 2544 | } |
| 2545 | while( s.n>0 ){ |
| 2546 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -249,10 +249,13 @@ | |
| 249 | #define MUTYPE_TR 0x0080 /* <tr> */ |
| 250 | #define MUTYPE_TD 0x0100 /* <td> or <th> */ |
| 251 | #define MUTYPE_SPECIAL 0x0200 /* <nowiki> or <verbatim> */ |
| 252 | #define MUTYPE_HYPERLINK 0x0400 /* <a> */ |
| 253 | |
| 254 | /* MUTYPE values for elements that require strictly nested end-tags */ |
| 255 | #define MUTYPE_Nested 0x0656 |
| 256 | |
| 257 | /* |
| 258 | ** These markup types must have an end tag. |
| 259 | */ |
| 260 | #define MUTYPE_STACK (MUTYPE_BLOCK | MUTYPE_FONT | MUTYPE_LIST | MUTYPE_TABLE) |
| 261 | |
| @@ -2423,10 +2426,11 @@ | |
| 2426 | |
| 2427 | /* |
| 2428 | ** Push a new element onto the tag statk |
| 2429 | */ |
| 2430 | void html_tagstack_push(HtmlTagStack *p, int e){ |
| 2431 | if( (aMarkup[e].iType & MUTYPE_Nested)==0 ) return; |
| 2432 | if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){ |
| 2433 | if( p->nAlloc==0 ){ |
| 2434 | int *aNew; |
| 2435 | p->nAlloc = 50; |
| 2436 | aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc ); |
| @@ -2462,19 +2466,20 @@ | |
| 2466 | ** If there is no open-tag for eEnd on the stack, then this |
| 2467 | ** routine is a no-op. |
| 2468 | */ |
| 2469 | void html_tagstack_pop(HtmlTagStack *p, Blob *pBlob, int eEnd){ |
| 2470 | int i; |
| 2471 | if( (aMarkup[eEnd].iType & MUTYPE_Nested)==0 ) return; |
| 2472 | for(i=p->n-1; i>=0 && p->aStack[i]!=eEnd; i--){} |
| 2473 | if( i<0 ){ |
| 2474 | blob_appendf(pBlob, "<span class='error'></%s></span>", |
| 2475 | aMarkup[eEnd].zName); |
| 2476 | return; |
| 2477 | } |
| 2478 | do{ |
| 2479 | p->n--; |
| 2480 | blob_appendf(pBlob, "</%s>", aMarkup[p->aStack[p->n]].zName); |
| 2481 | }while( p->aStack[p->n]!=eEnd ); |
| 2482 | } |
| 2483 | |
| 2484 | /* |
| 2485 | ** Append HTML text to a Blob object. The appended text is modified |
| @@ -2533,13 +2538,11 @@ | |
| 2538 | }else{ |
| 2539 | if( markup.endTag ){ |
| 2540 | html_tagstack_pop(&s, pBlob, markup.iCode); |
| 2541 | }else{ |
| 2542 | renderMarkup(pBlob, &markup); |
| 2543 | html_tagstack_push(&s, markup.iCode); |
| 2544 | } |
| 2545 | } |
| 2546 | unparseMarkup(&markup); |
| 2547 | } |
| 2548 | while( s.n>0 ){ |
| 2549 |