Fossil SCM

Further improvements to the end-tag insertion algorithm.

drh 2020-06-01 19:31 trunk
Commit a7ebb8d77fc6f55a01fd82e3fa70cfb033a53cc1fd4e691d0fe082b1a51fe2aa
1 file changed +16 -16
+16 -16
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -2426,11 +2426,10 @@
24262426
24272427
/*
24282428
** Push a new element onto the tag statk
24292429
*/
24302430
void html_tagstack_push(HtmlTagStack *p, int e){
2431
- if( (aMarkup[e].iType & MUTYPE_Nested)==0 ) return;
24322431
if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){
24332432
if( p->nAlloc==0 ){
24342433
int *aNew;
24352434
p->nAlloc = 50;
24362435
aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc );
@@ -2465,22 +2464,27 @@
24652464
**
24662465
** If there is no open-tag for eEnd on the stack, then this
24672466
** routine is a no-op.
24682467
*/
24692468
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'>&lt;/%s&gt;</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'>&lt;/%s&gt;</span>",
2474
+ aMarkup[eEnd].zName);
2475
+ return;
2476
+ }
2477
+ }else if( p->n==0 ){
24762478
return;
24772479
}
24782480
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 );
24822486
}
24832487
24842488
/*
24852489
** Append HTML text to a Blob object. The appended text is modified
24862490
** changed in the following ways:
@@ -2490,12 +2494,11 @@
24902494
** 2. Omit any attributes that are not on the AllowedMarkup list.
24912495
**
24922496
** 3. Omit any surplus close-tags.
24932497
**
24942498
** 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.
24972500
**
24982501
** The input must be writable. Temporary changes may be made to the
24992502
** input, but the input is restored to its original state prior to
25002503
** returning. If zHtml[nHtml] is not a zero character, then a zero
25012504
** might be written in that position temporarily, but that slot will
@@ -2543,14 +2546,11 @@
25432546
html_tagstack_push(&s, markup.iCode);
25442547
}
25452548
}
25462549
unparseMarkup(&markup);
25472550
}
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);
25522552
html_tagstack_clear(&s);
25532553
zHtml[nHtml] = cLast;
25542554
}
25552555
25562556
25572557
--- 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'>&lt;/%s&gt;</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'>&lt;/%s&gt;</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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button