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