Fossil SCM

Improvements to automatic end-tags.

drh 2020-06-01 19:16 trunk
Commit a7807a8b9c440d37a985e60a11de69abac9ac7029fe8553d3b2b658a827a9f2a
1 file changed +7 -4
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -249,10 +249,13 @@
249249
#define MUTYPE_TR 0x0080 /* <tr> */
250250
#define MUTYPE_TD 0x0100 /* <td> or <th> */
251251
#define MUTYPE_SPECIAL 0x0200 /* <nowiki> or <verbatim> */
252252
#define MUTYPE_HYPERLINK 0x0400 /* <a> */
253253
254
+/* MUTYPE values for elements that require strictly nested end-tags */
255
+#define MUTYPE_Nested 0x0656
256
+
254257
/*
255258
** These markup types must have an end tag.
256259
*/
257260
#define MUTYPE_STACK (MUTYPE_BLOCK | MUTYPE_FONT | MUTYPE_LIST | MUTYPE_TABLE)
258261
@@ -2423,10 +2426,11 @@
24232426
24242427
/*
24252428
** Push a new element onto the tag statk
24262429
*/
24272430
void html_tagstack_push(HtmlTagStack *p, int e){
2431
+ if( (aMarkup[e].iType & MUTYPE_Nested)==0 ) return;
24282432
if( p->n>=ArraySize(p->aSpace) && p->n>=p->nAlloc ){
24292433
if( p->nAlloc==0 ){
24302434
int *aNew;
24312435
p->nAlloc = 50;
24322436
aNew = fossil_malloc( sizeof(p->aStack[0])*p->nAlloc );
@@ -2462,19 +2466,20 @@
24622466
** If there is no open-tag for eEnd on the stack, then this
24632467
** routine is a no-op.
24642468
*/
24652469
void html_tagstack_pop(HtmlTagStack *p, Blob *pBlob, int eEnd){
24662470
int i;
2471
+ if( (aMarkup[eEnd].iType & MUTYPE_Nested)==0 ) return;
24672472
for(i=p->n-1; i>=0 && p->aStack[i]!=eEnd; i--){}
24682473
if( i<0 ){
24692474
blob_appendf(pBlob, "<span class='error'>&lt;/%s&gt;</span>",
24702475
aMarkup[eEnd].zName);
24712476
return;
24722477
}
24732478
do{
24742479
p->n--;
2475
- blob_appendf(pBlob, "</%s>", aMarkup[eEnd].zName);
2480
+ blob_appendf(pBlob, "</%s>", aMarkup[p->aStack[p->n]].zName);
24762481
}while( p->aStack[p->n]!=eEnd );
24772482
}
24782483
24792484
/*
24802485
** Append HTML text to a Blob object. The appended text is modified
@@ -2533,13 +2538,11 @@
25332538
}else{
25342539
if( markup.endTag ){
25352540
html_tagstack_pop(&s, pBlob, markup.iCode);
25362541
}else{
25372542
renderMarkup(pBlob, &markup);
2538
- if( markup.iType!=MUTYPE_SINGLE ){
2539
- html_tagstack_push(&s, markup.iCode);
2540
- }
2543
+ html_tagstack_push(&s, markup.iCode);
25412544
}
25422545
}
25432546
unparseMarkup(&markup);
25442547
}
25452548
while( s.n>0 ){
25462549
--- 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'>&lt;/%s&gt;</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'>&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
@@ -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

Keyboard Shortcuts

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