Fossil SCM
Further improvements to the end-tag insertion algorithm.
Commit
a7ebb8d77fc6f55a01fd82e3fa70cfb033a53cc1fd4e691d0fe082b1a51fe2aa
Parent
a7807a8b9c440d3…
1 file changed
+16
-16
+16
-16
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -2426,11 +2426,10 @@ | ||
| 2426 | 2426 | |
| 2427 | 2427 | /* |
| 2428 | 2428 | ** Push a new element onto the tag statk |
| 2429 | 2429 | */ |
| 2430 | 2430 | void html_tagstack_push(HtmlTagStack *p, int e){ |
| 2431 | - if( (aMarkup[e].iType & MUTYPE_Nested)==0 ) return; | |
| 2432 | 2431 | if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){ |
| 2433 | 2432 | if( p->nAlloc==0 ){ |
| 2434 | 2433 | int *aNew; |
| 2435 | 2434 | p->nAlloc = 50; |
| 2436 | 2435 | aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc ); |
| @@ -2465,22 +2464,27 @@ | ||
| 2465 | 2464 | ** |
| 2466 | 2465 | ** If there is no open-tag for eEnd on the stack, then this |
| 2467 | 2466 | ** routine is a no-op. |
| 2468 | 2467 | */ |
| 2469 | 2468 | 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); | |
| 2469 | + int i, e; | |
| 2470 | + if( eEnd!=0 ){ | |
| 2471 | + for(i=p->n-1; i>=0 && p->aStack[i]!=eEnd; i--){} | |
| 2472 | + if( i<0 ){ | |
| 2473 | + blob_appendf(pBlob, "<span class='error'></%s></span>", | |
| 2474 | + aMarkup[eEnd].zName); | |
| 2475 | + return; | |
| 2476 | + } | |
| 2477 | + }else if( p->n==0 ){ | |
| 2476 | 2478 | return; |
| 2477 | 2479 | } |
| 2478 | 2480 | do{ |
| 2479 | - p->n--; | |
| 2480 | - blob_appendf(pBlob, "</%s>", aMarkup[p->aStack[p->n]].zName); | |
| 2481 | - }while( p->aStack[p->n]!=eEnd ); | |
| 2481 | + e = p->aStack[--p->n]; | |
| 2482 | + if( e==eEnd || (aMarkup[e].iType & MUTYPE_Nested)!=0 ){ | |
| 2483 | + blob_appendf(pBlob, "</%s>", aMarkup[e].zName); | |
| 2484 | + } | |
| 2485 | + }while( e!=eEnd && p->n>0 ); | |
| 2482 | 2486 | } |
| 2483 | 2487 | |
| 2484 | 2488 | /* |
| 2485 | 2489 | ** Append HTML text to a Blob object. The appended text is modified |
| 2486 | 2490 | ** changed in the following ways: |
| @@ -2490,12 +2494,11 @@ | ||
| 2490 | 2494 | ** 2. Omit any attributes that are not on the AllowedMarkup list. |
| 2491 | 2495 | ** |
| 2492 | 2496 | ** 3. Omit any surplus close-tags. |
| 2493 | 2497 | ** |
| 2494 | 2498 | ** 4. Insert additional close-tags as necessary so that all |
| 2495 | -** non-empty tags in the input have a corresponding close tag. | |
| 2496 | -** Non-empty tags are elements other than <br>, <hr>, <img>, etc. | |
| 2499 | +** tag in the input that needs a close-tag has one. | |
| 2497 | 2500 | ** |
| 2498 | 2501 | ** The input must be writable. Temporary changes may be made to the |
| 2499 | 2502 | ** input, but the input is restored to its original state prior to |
| 2500 | 2503 | ** returning. If zHtml[nHtml] is not a zero character, then a zero |
| 2501 | 2504 | ** might be written in that position temporarily, but that slot will |
| @@ -2543,14 +2546,11 @@ | ||
| 2543 | 2546 | html_tagstack_push(&s, markup.iCode); |
| 2544 | 2547 | } |
| 2545 | 2548 | } |
| 2546 | 2549 | unparseMarkup(&markup); |
| 2547 | 2550 | } |
| 2548 | - while( s.n>0 ){ | |
| 2549 | - s.n--; | |
| 2550 | - blob_appendf(pBlob, "</%s>", aMarkup[s.aStack[s.n]]); | |
| 2551 | - } | |
| 2551 | + html_tagstack_pop(&s, pBlob, 0); | |
| 2552 | 2552 | html_tagstack_clear(&s); |
| 2553 | 2553 | zHtml[nHtml] = cLast; |
| 2554 | 2554 | } |
| 2555 | 2555 | |
| 2556 | 2556 | |
| 2557 | 2557 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -2426,11 +2426,10 @@ | |
| 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 ); |
| @@ -2465,22 +2464,27 @@ | |
| 2465 | ** |
| 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 |
| 2486 | ** changed in the following ways: |
| @@ -2490,12 +2494,11 @@ | |
| 2490 | ** 2. Omit any attributes that are not on the AllowedMarkup list. |
| 2491 | ** |
| 2492 | ** 3. Omit any surplus close-tags. |
| 2493 | ** |
| 2494 | ** 4. Insert additional close-tags as necessary so that all |
| 2495 | ** non-empty tags in the input have a corresponding close tag. |
| 2496 | ** Non-empty tags are elements other than <br>, <hr>, <img>, etc. |
| 2497 | ** |
| 2498 | ** The input must be writable. Temporary changes may be made to the |
| 2499 | ** input, but the input is restored to its original state prior to |
| 2500 | ** returning. If zHtml[nHtml] is not a zero character, then a zero |
| 2501 | ** might be written in that position temporarily, but that slot will |
| @@ -2543,14 +2546,11 @@ | |
| 2543 | html_tagstack_push(&s, markup.iCode); |
| 2544 | } |
| 2545 | } |
| 2546 | unparseMarkup(&markup); |
| 2547 | } |
| 2548 | while( s.n>0 ){ |
| 2549 | s.n--; |
| 2550 | blob_appendf(pBlob, "</%s>", aMarkup[s.aStack[s.n]]); |
| 2551 | } |
| 2552 | html_tagstack_clear(&s); |
| 2553 | zHtml[nHtml] = cLast; |
| 2554 | } |
| 2555 | |
| 2556 | |
| 2557 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -2426,11 +2426,10 @@ | |
| 2426 | |
| 2427 | /* |
| 2428 | ** Push a new element onto the tag statk |
| 2429 | */ |
| 2430 | void html_tagstack_push(HtmlTagStack *p, int e){ |
| 2431 | if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){ |
| 2432 | if( p->nAlloc==0 ){ |
| 2433 | int *aNew; |
| 2434 | p->nAlloc = 50; |
| 2435 | aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc ); |
| @@ -2465,22 +2464,27 @@ | |
| 2464 | ** |
| 2465 | ** If there is no open-tag for eEnd on the stack, then this |
| 2466 | ** routine is a no-op. |
| 2467 | */ |
| 2468 | void html_tagstack_pop(HtmlTagStack *p, Blob *pBlob, int eEnd){ |
| 2469 | int i, e; |
| 2470 | if( eEnd!=0 ){ |
| 2471 | for(i=p->n-1; i>=0 && p->aStack[i]!=eEnd; i--){} |
| 2472 | if( i<0 ){ |
| 2473 | blob_appendf(pBlob, "<span class='error'></%s></span>", |
| 2474 | aMarkup[eEnd].zName); |
| 2475 | return; |
| 2476 | } |
| 2477 | }else if( p->n==0 ){ |
| 2478 | return; |
| 2479 | } |
| 2480 | do{ |
| 2481 | e = p->aStack[--p->n]; |
| 2482 | if( e==eEnd || (aMarkup[e].iType & MUTYPE_Nested)!=0 ){ |
| 2483 | blob_appendf(pBlob, "</%s>", aMarkup[e].zName); |
| 2484 | } |
| 2485 | }while( e!=eEnd && p->n>0 ); |
| 2486 | } |
| 2487 | |
| 2488 | /* |
| 2489 | ** Append HTML text to a Blob object. The appended text is modified |
| 2490 | ** changed in the following ways: |
| @@ -2490,12 +2494,11 @@ | |
| 2494 | ** 2. Omit any attributes that are not on the AllowedMarkup list. |
| 2495 | ** |
| 2496 | ** 3. Omit any surplus close-tags. |
| 2497 | ** |
| 2498 | ** 4. Insert additional close-tags as necessary so that all |
| 2499 | ** tag in the input that needs a close-tag has one. |
| 2500 | ** |
| 2501 | ** The input must be writable. Temporary changes may be made to the |
| 2502 | ** input, but the input is restored to its original state prior to |
| 2503 | ** returning. If zHtml[nHtml] is not a zero character, then a zero |
| 2504 | ** might be written in that position temporarily, but that slot will |
| @@ -2543,14 +2546,11 @@ | |
| 2546 | html_tagstack_push(&s, markup.iCode); |
| 2547 | } |
| 2548 | } |
| 2549 | unparseMarkup(&markup); |
| 2550 | } |
| 2551 | html_tagstack_pop(&s, pBlob, 0); |
| 2552 | html_tagstack_clear(&s); |
| 2553 | zHtml[nHtml] = cLast; |
| 2554 | } |
| 2555 | |
| 2556 | |
| 2557 |