Fossil SCM

Minor refactoring. Move the definition of <code>BLOB_APPEND_LITERAL()</code> macro from <code>markdown_html.c</code> to <code>blob.c</code> so that it could be used outside of <code>markdown_html.c</code>. Also rename it to lowercase for consistency with other API. Within <code>markdown.c</code> use that newly available macro instead of <code>blob_append_string()</code>. Within <code>markdown_html.c</code> use it for footnotes-relevant code. Other invocations of <code>BLOB_APPEND_LITERAL()</code> within <code>markdown_html.c</code> are left intact (they use an alias) in order to simplify the potential merge with the trunk.

george 2022-02-23 09:45 markdown-footnotes
Commit c8a8d0c94cf5f055f5242d0d7b61b6422eb424ed4f6655b2c941077f89244968
+17 -7
--- src/blob.c
+++ src/blob.c
@@ -59,10 +59,27 @@
5959
** Append blob contents to another
6060
*/
6161
#define blob_appendb(dest, src) \
6262
blob_append((dest), blob_buffer(src), blob_size(src))
6363
64
+/*
65
+** Append a string literal to a blob
66
+** TODO: Consider renaming to blob_appendl()
67
+*/
68
+#define blob_append_literal(blob, literal) \
69
+ blob_append((blob), "" literal, (sizeof literal)-1)
70
+ /*
71
+ * The empty string in the second argument leads to a syntax error
72
+ * when the macro is not used with a string literal. Unfortunately
73
+ * the error is not overly explicit.
74
+ */
75
+
76
+/*
77
+** TODO: Suggested for removal because the name seems misleading.
78
+*/
79
+#define blob_append_string blob_append_literal
80
+
6481
/*
6582
** Seek whence parameter values
6683
*/
6784
#define BLOB_SEEK_SET 1
6885
#define BLOB_SEEK_CUR 2
@@ -331,17 +348,10 @@
331348
pBlob->nUsed += nData;
332349
pBlob->aData[pBlob->nUsed] = 0;
333350
memcpy(&pBlob->aData[nUsed], aData, nData);
334351
}
335352
336
-/*
337
-** Append a string literal to a blob.
338
-*/
339
-#if INTERFACE
340
-#define blob_append_string(BLOB,STR) blob_append(BLOB,STR,sizeof(STR)-1)
341
-#endif
342
-
343353
/*
344354
** Append a single character to the blob. If pBlob is zero then the
345355
** character is written directly to stdout.
346356
*/
347357
void blob_append_char(Blob *pBlob, char c){
348358
--- src/blob.c
+++ src/blob.c
@@ -59,10 +59,27 @@
59 ** Append blob contents to another
60 */
61 #define blob_appendb(dest, src) \
62 blob_append((dest), blob_buffer(src), blob_size(src))
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64 /*
65 ** Seek whence parameter values
66 */
67 #define BLOB_SEEK_SET 1
68 #define BLOB_SEEK_CUR 2
@@ -331,17 +348,10 @@
331 pBlob->nUsed += nData;
332 pBlob->aData[pBlob->nUsed] = 0;
333 memcpy(&pBlob->aData[nUsed], aData, nData);
334 }
335
336 /*
337 ** Append a string literal to a blob.
338 */
339 #if INTERFACE
340 #define blob_append_string(BLOB,STR) blob_append(BLOB,STR,sizeof(STR)-1)
341 #endif
342
343 /*
344 ** Append a single character to the blob. If pBlob is zero then the
345 ** character is written directly to stdout.
346 */
347 void blob_append_char(Blob *pBlob, char c){
348
--- src/blob.c
+++ src/blob.c
@@ -59,10 +59,27 @@
59 ** Append blob contents to another
60 */
61 #define blob_appendb(dest, src) \
62 blob_append((dest), blob_buffer(src), blob_size(src))
63
64 /*
65 ** Append a string literal to a blob
66 ** TODO: Consider renaming to blob_appendl()
67 */
68 #define blob_append_literal(blob, literal) \
69 blob_append((blob), "" literal, (sizeof literal)-1)
70 /*
71 * The empty string in the second argument leads to a syntax error
72 * when the macro is not used with a string literal. Unfortunately
73 * the error is not overly explicit.
74 */
75
76 /*
77 ** TODO: Suggested for removal because the name seems misleading.
78 */
79 #define blob_append_string blob_append_literal
80
81 /*
82 ** Seek whence parameter values
83 */
84 #define BLOB_SEEK_SET 1
85 #define BLOB_SEEK_CUR 2
@@ -331,17 +348,10 @@
348 pBlob->nUsed += nData;
349 pBlob->aData[pBlob->nUsed] = 0;
350 memcpy(&pBlob->aData[nUsed], aData, nData);
351 }
352
 
 
 
 
 
 
 
353 /*
354 ** Append a single character to the blob. If pBlob is zero then the
355 ** character is written directly to stdout.
356 */
357 void blob_append_char(Blob *pBlob, char c){
358
+4 -4
--- src/markdown.c
+++ src/markdown.c
@@ -2687,26 +2687,26 @@
26872687
}
26882688
if( i+1<j ){
26892689
Blob list = empty_blob;
26902690
blob_reserve(&list, k);
26912691
/* must match _joined_footnote_indicator in html_footnote_item() */
2692
- blob_append_string(&list, "<ul class='fn-joined'>\n");
2692
+ blob_append_literal(&list, "<ul class='fn-joined'>\n");
26932693
for(k=i; k<j; k++){
26942694
struct footnote *y = fn + k;
2695
- blob_append_string(&list, "<li>");
2695
+ blob_append_literal(&list, "<li>");
26962696
if( blob_size(&y->upc) ){
26972697
blob_appendb(&list, &y->upc);
26982698
blob_reset(&y->upc);
26992699
}
27002700
blob_appendb(&list, &y->text);
2701
- blob_append_string(&list, "</li>\n");
2701
+ blob_append_literal(&list, "</li>\n");
27022702
27032703
/* free memory buffer */
27042704
blob_reset(&y->text);
27052705
if( k!=i ) blob_reset(&y->id);
27062706
}
2707
- blob_append_string(&list, "</ul>\n");
2707
+ blob_append_literal(&list, "</ul>\n");
27082708
x->text = list;
27092709
g.ftntsIssues[2]++;
27102710
}
27112711
i = j;
27122712
}
27132713
--- src/markdown.c
+++ src/markdown.c
@@ -2687,26 +2687,26 @@
2687 }
2688 if( i+1<j ){
2689 Blob list = empty_blob;
2690 blob_reserve(&list, k);
2691 /* must match _joined_footnote_indicator in html_footnote_item() */
2692 blob_append_string(&list, "<ul class='fn-joined'>\n");
2693 for(k=i; k<j; k++){
2694 struct footnote *y = fn + k;
2695 blob_append_string(&list, "<li>");
2696 if( blob_size(&y->upc) ){
2697 blob_appendb(&list, &y->upc);
2698 blob_reset(&y->upc);
2699 }
2700 blob_appendb(&list, &y->text);
2701 blob_append_string(&list, "</li>\n");
2702
2703 /* free memory buffer */
2704 blob_reset(&y->text);
2705 if( k!=i ) blob_reset(&y->id);
2706 }
2707 blob_append_string(&list, "</ul>\n");
2708 x->text = list;
2709 g.ftntsIssues[2]++;
2710 }
2711 i = j;
2712 }
2713
--- src/markdown.c
+++ src/markdown.c
@@ -2687,26 +2687,26 @@
2687 }
2688 if( i+1<j ){
2689 Blob list = empty_blob;
2690 blob_reserve(&list, k);
2691 /* must match _joined_footnote_indicator in html_footnote_item() */
2692 blob_append_literal(&list, "<ul class='fn-joined'>\n");
2693 for(k=i; k<j; k++){
2694 struct footnote *y = fn + k;
2695 blob_append_literal(&list, "<li>");
2696 if( blob_size(&y->upc) ){
2697 blob_appendb(&list, &y->upc);
2698 blob_reset(&y->upc);
2699 }
2700 blob_appendb(&list, &y->text);
2701 blob_append_literal(&list, "</li>\n");
2702
2703 /* free memory buffer */
2704 blob_reset(&y->text);
2705 if( k!=i ) blob_reset(&y->id);
2706 }
2707 blob_append_literal(&list, "</ul>\n");
2708 x->text = list;
2709 g.ftntsIssues[2]++;
2710 }
2711 i = j;
2712 }
2713
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -50,21 +50,17 @@
5050
5151
/* INTER_BLOCK -- skip a line between block level elements */
5252
#define INTER_BLOCK(ob) \
5353
do { if( blob_size(ob)>0 ) blob_append_char(ob, '\n'); } while (0)
5454
55
-/* BLOB_APPEND_LITERAL -- append a string literal to a blob */
56
-#define BLOB_APPEND_LITERAL(blob, literal) \
57
- blob_append((blob), "" literal, (sizeof literal)-1)
58
- /*
59
- * The empty string in the second argument leads to a syntax error
60
- * when the macro is not used with a string literal. Unfortunately
61
- * the error is not overly explicit.
62
- */
55
+/* BLOB_APPEND_LITERAL -- append a string literal to a blob
56
+** TODO: Refactor all invocations to use global macro blob_append_literal()
57
+*/
58
+#define BLOB_APPEND_LITERAL blob_append_literal
6359
6460
/* BLOB_APPEND_BLOB -- append blob contents to another
65
-** TODO: Refactor all invocations to use globall macro blob_appendb()
61
+** TODO: Refactor all invocations to use global macro blob_appendb()
6662
*/
6763
#define BLOB_APPEND_BLOB(dest, src) blob_appendb((dest), (src))
6864
6965
#ifndef FOOTNOTES_WITHOUT_URI
7066
#define BLOB_APPEND_URI(dest,ctx) blob_appendb(dest,&((ctx)->reqURI))
@@ -350,11 +346,11 @@
350346
int i, n = blob_size(upc);
351347
if( n<3 ) return;
352348
assert( z[0]=='.' && z[n-1] == ':' );
353349
354350
if( bHTML ){
355
- BLOB_APPEND_LITERAL(ob, "<span class='fn-upc'>"
351
+ blob_append_literal(ob, "<span class='fn-upc'>"
356352
"<span class='fn-upcDot'>.</span>");
357353
}
358354
n = 0;
359355
do{
360356
z++;
@@ -362,33 +358,33 @@
362358
assert( fossil_isalnum(*z) || *z=='-' );
363359
n++;
364360
continue;
365361
}
366362
assert( n );
367
- if( bHTML ) BLOB_APPEND_LITERAL(ob, "<span class='");
368
- BLOB_APPEND_LITERAL(ob, "fn-upc-");
363
+ if( bHTML ) blob_append_literal(ob, "<span class='");
364
+ blob_append_literal(ob, "fn-upc-");
369365
370366
for(i=-n; i<0; i++){
371367
blob_append_char(ob, fossil_tolower(z[i]) );
372368
}
373369
if( bHTML ){
374
- BLOB_APPEND_LITERAL(ob, "'>");
370
+ blob_append_literal(ob, "'>");
375371
blob_append(ob, z-n, n);
376
- BLOB_APPEND_LITERAL(ob, "</span>");
372
+ blob_append_literal(ob, "</span>");
377373
}else{
378374
blob_append_char(ob, ' ');
379375
}
380376
n = 0;
381377
if( bHTML ){
382378
if( *z==':' ){
383
- BLOB_APPEND_LITERAL(ob,"<span class='fn-upcColon'>:</span>");
379
+ blob_append_literal(ob,"<span class='fn-upcColon'>:</span>");
384380
}else{
385
- BLOB_APPEND_LITERAL(ob,"<span class='fn-upcDot'>.</span>");
381
+ blob_append_literal(ob,"<span class='fn-upcDot'>.</span>");
386382
}
387383
}
388384
}while( *z != ':' );
389
- if( bHTML ) BLOB_APPEND_LITERAL(ob,"</span>\n");
385
+ if( bHTML ) blob_append_literal(ob,"</span>\n");
390386
}
391387
392388
static int html_footnote_ref(
393389
struct Blob *ob, const struct Blob *span, const struct Blob *upc,
394390
int iMark, int locus, void *opaque
@@ -401,24 +397,24 @@
401397
/* expect BUGs if the following yields compiler warnings */
402398
if( iMark > 0 ){ /* a regular reference to a footnote */
403399
404400
sprintf(pos, "%s-%i-%s", ctx->unique.c, iMark, l.c);
405401
if(span && blob_size(span)) {
406
- BLOB_APPEND_LITERAL(ob,"<span class='");
402
+ blob_append_literal(ob,"<span class='");
407403
append_footnote_upc(ob, upc, 0);
408
- BLOB_APPEND_LITERAL(ob,"notescope' id='noteref");
404
+ blob_append_literal(ob,"notescope' id='noteref");
409405
blob_appendf(ob,"%s'>",pos);
410406
blob_appendb(ob, span);
411407
blob_trim(ob);
412
- BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
408
+ blob_append_literal(ob,"<sup class='noteref'><a href='");
413409
BLOB_APPEND_URI(ob, ctx);
414410
blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
415411
}else{
416412
blob_trim(ob);
417
- BLOB_APPEND_LITERAL(ob,"<sup class='");
413
+ blob_append_literal(ob,"<sup class='");
418414
append_footnote_upc(ob, upc, 0);
419
- BLOB_APPEND_LITERAL(ob,"noteref'><a href='");
415
+ blob_append_literal(ob,"noteref'><a href='");
420416
BLOB_APPEND_URI(ob, ctx);
421417
blob_appendf(ob,"#footnote%s' id='noteref%s'>%i</a></sup>",
422418
pos, pos, iMark);
423419
}
424420
}else{ /* misreference */
@@ -427,19 +423,19 @@
427423
sprintf(pos, "%s-%s", ctx->unique.c, l.c);
428424
if(span && blob_size(span)) {
429425
blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
430426
blob_appendb(ob, span);
431427
blob_trim(ob);
432
- BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
428
+ blob_append_literal(ob, "<sup class='noteref misref'><a href='");
433429
BLOB_APPEND_URI(ob, ctx);
434430
blob_appendf(ob, "#misreference%s'>misref</a></sup></span>", pos);
435431
}else{
436432
blob_trim(ob);
437
- BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
433
+ blob_append_literal(ob, "<sup class='noteref misref'><a href='");
438434
BLOB_APPEND_URI(ob, ctx);
439435
blob_appendf(ob, "#misreference%s' id='misref%s'>", pos, pos);
440
- BLOB_APPEND_LITERAL(ob, "misref</a></sup>");
436
+ blob_append_literal(ob, "misref</a></sup>");
441437
}
442438
}
443439
return 1;
444440
}
445441
@@ -456,11 +452,11 @@
456452
/* expect BUGs if the following yields compiler warnings */
457453
458454
if( iMark < 0 ){ /* misreferences */
459455
assert( iMark == -1 );
460456
assert( nUsed );
461
- BLOB_APPEND_LITERAL(ob,"<li class='fn-misreference'>"
457
+ blob_append_literal(ob,"<li class='fn-misreference'>"
462458
"<sup class='fn-backrefs'>");
463459
if( nUsed == 1 ){
464460
blob_appendf(ob,"<a id='misreference%s-a' href='", unique);
465461
BLOB_APPEND_URI(ob, ctx);
466462
blob_appendf(ob,"#misref%s-a'>^</a>", unique);
@@ -471,13 +467,13 @@
471467
const int c = i + (unsigned)'a';
472468
blob_appendf(ob," <a id='misreference%s-%c' href='", unique,c);
473469
BLOB_APPEND_URI(ob, ctx);
474470
blob_appendf(ob,"#misref%s-%c'>%c</a>", unique,c, c);
475471
}
476
- if( i < nUsed ) BLOB_APPEND_LITERAL(ob," &hellip;");
472
+ if( i < nUsed ) blob_append_literal(ob," &hellip;");
477473
}
478
- BLOB_APPEND_LITERAL(ob,"</sup>\n<span>Misreference</span>");
474
+ blob_append_literal(ob,"</sup>\n<span>Misreference</span>");
479475
480476
}else if( iMark > 0 ){ /* regular, joined and overnested footnotes */
481477
char pos[24];
482478
int bJoin = 0;
483479
#define _joined_footnote_indicator "<ul class='fn-joined'>"
@@ -490,25 +486,25 @@
490486
blob_appendf(ob, "<li id='footnote%s' class='", pos);
491487
if( nUsed ){
492488
if( blob_size(text)>=_jfi_sz &&
493489
!memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
494490
bJoin = 1;
495
- BLOB_APPEND_LITERAL(ob, "fn-joined ");
491
+ blob_append_literal(ob, "fn-joined ");
496492
}
497493
append_footnote_upc(ob, upc, 0);
498494
}else{
499
- BLOB_APPEND_LITERAL(ob, "fn-toodeep ");
495
+ blob_append_literal(ob, "fn-toodeep ");
500496
}
501497
502498
if( nUsed <= 1 ){
503
- BLOB_APPEND_LITERAL(ob, "fn-monoref'><sup class='fn-backrefs'>");
499
+ blob_append_literal(ob, "fn-monoref'><sup class='fn-backrefs'>");
504500
blob_appendf(ob,"<a id='footnote%s-a' href='", pos);
505501
BLOB_APPEND_URI(ob, ctx);
506502
blob_appendf(ob,"#noteref%s-a'>^</a>", pos);
507503
}else{
508504
int i;
509
- BLOB_APPEND_LITERAL(ob, "fn-polyref'><sup class='fn-backrefs'>^");
505
+ blob_append_literal(ob, "fn-polyref'><sup class='fn-backrefs'>^");
510506
for(i=0; i<nUsed && i<26; i++){
511507
const int c = i + (unsigned)'a';
512508
blob_appendf(ob," <a id='footnote%s-%c' href='", pos,c);
513509
BLOB_APPEND_URI(ob, ctx);
514510
blob_appendf(ob,"#noteref%s-%c'>%c</a>", pos,c, c);
@@ -519,27 +515,27 @@
519515
const bitfield64_t l = to_base26(i,0);
520516
blob_appendf(ob," <a id='footnote%s-%s' href='", pos, l.c);
521517
BLOB_APPEND_URI(ob, ctx);
522518
blob_appendf(ob,"#noteref%s-%s'>%s</a>", pos,l.c, l.c);
523519
}
524
- if( i < nUsed ) BLOB_APPEND_LITERAL(ob," &hellip;");
520
+ if( i < nUsed ) blob_append_literal(ob," &hellip;");
525521
}
526
- BLOB_APPEND_LITERAL(ob,"</sup>\n");
522
+ blob_append_literal(ob,"</sup>\n");
527523
if( bJoin ){
528
- BLOB_APPEND_LITERAL(ob,"<sup class='fn-joined'></sup><ul>");
524
+ blob_append_literal(ob,"<sup class='fn-joined'></sup><ul>");
529525
blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
530526
}else if( nUsed ){
531527
append_footnote_upc(ob, upc, 1);
532528
blob_appendb(ob, text);
533529
}else{
534
- BLOB_APPEND_LITERAL(ob,"<i></i>\n"
530
+ blob_append_literal(ob,"<i></i>\n"
535531
"<pre><code class='language-markdown'>");
536532
if( blob_size(upc) ){
537533
blob_appendb(ob, upc);
538534
}
539535
html_escape(ob, blob_buffer(text), blob_size(text));
540
- BLOB_APPEND_LITERAL(ob,"</code></pre>");
536
+ blob_append_literal(ob,"</code></pre>");
541537
}
542538
#undef _joined_footnote_indicator
543539
#undef _jfi_sz
544540
}else{ /* a footnote was defined but wasn't referenced */
545541
/* make.footnote_item() invocations should pass args accordingly */
@@ -546,30 +542,30 @@
546542
const struct Blob * id = text-1;
547543
assert( !nUsed );
548544
assert( text );
549545
assert( blob_size(text) );
550546
assert( blob_size(id) );
551
- BLOB_APPEND_LITERAL(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
547
+ blob_append_literal(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
552548
html_escape(ob, blob_buffer(id), blob_size(id));
553
- BLOB_APPEND_LITERAL(ob, "</code>&nbsp;]<i></i>\n"
549
+ blob_append_literal(ob, "</code>&nbsp;]<i></i>\n"
554550
"<pre><code class='language-markdown'>");
555551
if( blob_size(upc) ){
556552
blob_appendb(ob, upc);
557553
}
558554
html_escape(ob, blob_buffer(text), blob_size(text));
559
- BLOB_APPEND_LITERAL(ob,"</code></pre>");
555
+ blob_append_literal(ob,"</code></pre>");
560556
}
561
- BLOB_APPEND_LITERAL(ob, "\n</li>\n");
557
+ blob_append_literal(ob, "\n</li>\n");
562558
}
563559
static void html_footnotes(
564560
struct Blob *ob, const struct Blob *items, void *opaque
565561
){
566562
if( items && blob_size(items) ){
567
- BLOB_APPEND_LITERAL(ob,
563
+ blob_append_literal(ob,
568564
"\n<hr class='footnotes-separator'/>\n<ol class='footnotes'>\n");
569565
blob_appendb(ob, items);
570
- BLOB_APPEND_LITERAL(ob, "</ol>\n");
566
+ blob_append_literal(ob, "</ol>\n");
571567
}
572568
}
573569
574570
/* HTML span tags */
575571
576572
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -50,21 +50,17 @@
50
51 /* INTER_BLOCK -- skip a line between block level elements */
52 #define INTER_BLOCK(ob) \
53 do { if( blob_size(ob)>0 ) blob_append_char(ob, '\n'); } while (0)
54
55 /* BLOB_APPEND_LITERAL -- append a string literal to a blob */
56 #define BLOB_APPEND_LITERAL(blob, literal) \
57 blob_append((blob), "" literal, (sizeof literal)-1)
58 /*
59 * The empty string in the second argument leads to a syntax error
60 * when the macro is not used with a string literal. Unfortunately
61 * the error is not overly explicit.
62 */
63
64 /* BLOB_APPEND_BLOB -- append blob contents to another
65 ** TODO: Refactor all invocations to use globall macro blob_appendb()
66 */
67 #define BLOB_APPEND_BLOB(dest, src) blob_appendb((dest), (src))
68
69 #ifndef FOOTNOTES_WITHOUT_URI
70 #define BLOB_APPEND_URI(dest,ctx) blob_appendb(dest,&((ctx)->reqURI))
@@ -350,11 +346,11 @@
350 int i, n = blob_size(upc);
351 if( n<3 ) return;
352 assert( z[0]=='.' && z[n-1] == ':' );
353
354 if( bHTML ){
355 BLOB_APPEND_LITERAL(ob, "<span class='fn-upc'>"
356 "<span class='fn-upcDot'>.</span>");
357 }
358 n = 0;
359 do{
360 z++;
@@ -362,33 +358,33 @@
362 assert( fossil_isalnum(*z) || *z=='-' );
363 n++;
364 continue;
365 }
366 assert( n );
367 if( bHTML ) BLOB_APPEND_LITERAL(ob, "<span class='");
368 BLOB_APPEND_LITERAL(ob, "fn-upc-");
369
370 for(i=-n; i<0; i++){
371 blob_append_char(ob, fossil_tolower(z[i]) );
372 }
373 if( bHTML ){
374 BLOB_APPEND_LITERAL(ob, "'>");
375 blob_append(ob, z-n, n);
376 BLOB_APPEND_LITERAL(ob, "</span>");
377 }else{
378 blob_append_char(ob, ' ');
379 }
380 n = 0;
381 if( bHTML ){
382 if( *z==':' ){
383 BLOB_APPEND_LITERAL(ob,"<span class='fn-upcColon'>:</span>");
384 }else{
385 BLOB_APPEND_LITERAL(ob,"<span class='fn-upcDot'>.</span>");
386 }
387 }
388 }while( *z != ':' );
389 if( bHTML ) BLOB_APPEND_LITERAL(ob,"</span>\n");
390 }
391
392 static int html_footnote_ref(
393 struct Blob *ob, const struct Blob *span, const struct Blob *upc,
394 int iMark, int locus, void *opaque
@@ -401,24 +397,24 @@
401 /* expect BUGs if the following yields compiler warnings */
402 if( iMark > 0 ){ /* a regular reference to a footnote */
403
404 sprintf(pos, "%s-%i-%s", ctx->unique.c, iMark, l.c);
405 if(span && blob_size(span)) {
406 BLOB_APPEND_LITERAL(ob,"<span class='");
407 append_footnote_upc(ob, upc, 0);
408 BLOB_APPEND_LITERAL(ob,"notescope' id='noteref");
409 blob_appendf(ob,"%s'>",pos);
410 blob_appendb(ob, span);
411 blob_trim(ob);
412 BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
413 BLOB_APPEND_URI(ob, ctx);
414 blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
415 }else{
416 blob_trim(ob);
417 BLOB_APPEND_LITERAL(ob,"<sup class='");
418 append_footnote_upc(ob, upc, 0);
419 BLOB_APPEND_LITERAL(ob,"noteref'><a href='");
420 BLOB_APPEND_URI(ob, ctx);
421 blob_appendf(ob,"#footnote%s' id='noteref%s'>%i</a></sup>",
422 pos, pos, iMark);
423 }
424 }else{ /* misreference */
@@ -427,19 +423,19 @@
427 sprintf(pos, "%s-%s", ctx->unique.c, l.c);
428 if(span && blob_size(span)) {
429 blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
430 blob_appendb(ob, span);
431 blob_trim(ob);
432 BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
433 BLOB_APPEND_URI(ob, ctx);
434 blob_appendf(ob, "#misreference%s'>misref</a></sup></span>", pos);
435 }else{
436 blob_trim(ob);
437 BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
438 BLOB_APPEND_URI(ob, ctx);
439 blob_appendf(ob, "#misreference%s' id='misref%s'>", pos, pos);
440 BLOB_APPEND_LITERAL(ob, "misref</a></sup>");
441 }
442 }
443 return 1;
444 }
445
@@ -456,11 +452,11 @@
456 /* expect BUGs if the following yields compiler warnings */
457
458 if( iMark < 0 ){ /* misreferences */
459 assert( iMark == -1 );
460 assert( nUsed );
461 BLOB_APPEND_LITERAL(ob,"<li class='fn-misreference'>"
462 "<sup class='fn-backrefs'>");
463 if( nUsed == 1 ){
464 blob_appendf(ob,"<a id='misreference%s-a' href='", unique);
465 BLOB_APPEND_URI(ob, ctx);
466 blob_appendf(ob,"#misref%s-a'>^</a>", unique);
@@ -471,13 +467,13 @@
471 const int c = i + (unsigned)'a';
472 blob_appendf(ob," <a id='misreference%s-%c' href='", unique,c);
473 BLOB_APPEND_URI(ob, ctx);
474 blob_appendf(ob,"#misref%s-%c'>%c</a>", unique,c, c);
475 }
476 if( i < nUsed ) BLOB_APPEND_LITERAL(ob," &hellip;");
477 }
478 BLOB_APPEND_LITERAL(ob,"</sup>\n<span>Misreference</span>");
479
480 }else if( iMark > 0 ){ /* regular, joined and overnested footnotes */
481 char pos[24];
482 int bJoin = 0;
483 #define _joined_footnote_indicator "<ul class='fn-joined'>"
@@ -490,25 +486,25 @@
490 blob_appendf(ob, "<li id='footnote%s' class='", pos);
491 if( nUsed ){
492 if( blob_size(text)>=_jfi_sz &&
493 !memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
494 bJoin = 1;
495 BLOB_APPEND_LITERAL(ob, "fn-joined ");
496 }
497 append_footnote_upc(ob, upc, 0);
498 }else{
499 BLOB_APPEND_LITERAL(ob, "fn-toodeep ");
500 }
501
502 if( nUsed <= 1 ){
503 BLOB_APPEND_LITERAL(ob, "fn-monoref'><sup class='fn-backrefs'>");
504 blob_appendf(ob,"<a id='footnote%s-a' href='", pos);
505 BLOB_APPEND_URI(ob, ctx);
506 blob_appendf(ob,"#noteref%s-a'>^</a>", pos);
507 }else{
508 int i;
509 BLOB_APPEND_LITERAL(ob, "fn-polyref'><sup class='fn-backrefs'>^");
510 for(i=0; i<nUsed && i<26; i++){
511 const int c = i + (unsigned)'a';
512 blob_appendf(ob," <a id='footnote%s-%c' href='", pos,c);
513 BLOB_APPEND_URI(ob, ctx);
514 blob_appendf(ob,"#noteref%s-%c'>%c</a>", pos,c, c);
@@ -519,27 +515,27 @@
519 const bitfield64_t l = to_base26(i,0);
520 blob_appendf(ob," <a id='footnote%s-%s' href='", pos, l.c);
521 BLOB_APPEND_URI(ob, ctx);
522 blob_appendf(ob,"#noteref%s-%s'>%s</a>", pos,l.c, l.c);
523 }
524 if( i < nUsed ) BLOB_APPEND_LITERAL(ob," &hellip;");
525 }
526 BLOB_APPEND_LITERAL(ob,"</sup>\n");
527 if( bJoin ){
528 BLOB_APPEND_LITERAL(ob,"<sup class='fn-joined'></sup><ul>");
529 blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
530 }else if( nUsed ){
531 append_footnote_upc(ob, upc, 1);
532 blob_appendb(ob, text);
533 }else{
534 BLOB_APPEND_LITERAL(ob,"<i></i>\n"
535 "<pre><code class='language-markdown'>");
536 if( blob_size(upc) ){
537 blob_appendb(ob, upc);
538 }
539 html_escape(ob, blob_buffer(text), blob_size(text));
540 BLOB_APPEND_LITERAL(ob,"</code></pre>");
541 }
542 #undef _joined_footnote_indicator
543 #undef _jfi_sz
544 }else{ /* a footnote was defined but wasn't referenced */
545 /* make.footnote_item() invocations should pass args accordingly */
@@ -546,30 +542,30 @@
546 const struct Blob * id = text-1;
547 assert( !nUsed );
548 assert( text );
549 assert( blob_size(text) );
550 assert( blob_size(id) );
551 BLOB_APPEND_LITERAL(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
552 html_escape(ob, blob_buffer(id), blob_size(id));
553 BLOB_APPEND_LITERAL(ob, "</code>&nbsp;]<i></i>\n"
554 "<pre><code class='language-markdown'>");
555 if( blob_size(upc) ){
556 blob_appendb(ob, upc);
557 }
558 html_escape(ob, blob_buffer(text), blob_size(text));
559 BLOB_APPEND_LITERAL(ob,"</code></pre>");
560 }
561 BLOB_APPEND_LITERAL(ob, "\n</li>\n");
562 }
563 static void html_footnotes(
564 struct Blob *ob, const struct Blob *items, void *opaque
565 ){
566 if( items && blob_size(items) ){
567 BLOB_APPEND_LITERAL(ob,
568 "\n<hr class='footnotes-separator'/>\n<ol class='footnotes'>\n");
569 blob_appendb(ob, items);
570 BLOB_APPEND_LITERAL(ob, "</ol>\n");
571 }
572 }
573
574 /* HTML span tags */
575
576
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -50,21 +50,17 @@
50
51 /* INTER_BLOCK -- skip a line between block level elements */
52 #define INTER_BLOCK(ob) \
53 do { if( blob_size(ob)>0 ) blob_append_char(ob, '\n'); } while (0)
54
55 /* BLOB_APPEND_LITERAL -- append a string literal to a blob
56 ** TODO: Refactor all invocations to use global macro blob_append_literal()
57 */
58 #define BLOB_APPEND_LITERAL blob_append_literal
 
 
 
 
59
60 /* BLOB_APPEND_BLOB -- append blob contents to another
61 ** TODO: Refactor all invocations to use global macro blob_appendb()
62 */
63 #define BLOB_APPEND_BLOB(dest, src) blob_appendb((dest), (src))
64
65 #ifndef FOOTNOTES_WITHOUT_URI
66 #define BLOB_APPEND_URI(dest,ctx) blob_appendb(dest,&((ctx)->reqURI))
@@ -350,11 +346,11 @@
346 int i, n = blob_size(upc);
347 if( n<3 ) return;
348 assert( z[0]=='.' && z[n-1] == ':' );
349
350 if( bHTML ){
351 blob_append_literal(ob, "<span class='fn-upc'>"
352 "<span class='fn-upcDot'>.</span>");
353 }
354 n = 0;
355 do{
356 z++;
@@ -362,33 +358,33 @@
358 assert( fossil_isalnum(*z) || *z=='-' );
359 n++;
360 continue;
361 }
362 assert( n );
363 if( bHTML ) blob_append_literal(ob, "<span class='");
364 blob_append_literal(ob, "fn-upc-");
365
366 for(i=-n; i<0; i++){
367 blob_append_char(ob, fossil_tolower(z[i]) );
368 }
369 if( bHTML ){
370 blob_append_literal(ob, "'>");
371 blob_append(ob, z-n, n);
372 blob_append_literal(ob, "</span>");
373 }else{
374 blob_append_char(ob, ' ');
375 }
376 n = 0;
377 if( bHTML ){
378 if( *z==':' ){
379 blob_append_literal(ob,"<span class='fn-upcColon'>:</span>");
380 }else{
381 blob_append_literal(ob,"<span class='fn-upcDot'>.</span>");
382 }
383 }
384 }while( *z != ':' );
385 if( bHTML ) blob_append_literal(ob,"</span>\n");
386 }
387
388 static int html_footnote_ref(
389 struct Blob *ob, const struct Blob *span, const struct Blob *upc,
390 int iMark, int locus, void *opaque
@@ -401,24 +397,24 @@
397 /* expect BUGs if the following yields compiler warnings */
398 if( iMark > 0 ){ /* a regular reference to a footnote */
399
400 sprintf(pos, "%s-%i-%s", ctx->unique.c, iMark, l.c);
401 if(span && blob_size(span)) {
402 blob_append_literal(ob,"<span class='");
403 append_footnote_upc(ob, upc, 0);
404 blob_append_literal(ob,"notescope' id='noteref");
405 blob_appendf(ob,"%s'>",pos);
406 blob_appendb(ob, span);
407 blob_trim(ob);
408 blob_append_literal(ob,"<sup class='noteref'><a href='");
409 BLOB_APPEND_URI(ob, ctx);
410 blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
411 }else{
412 blob_trim(ob);
413 blob_append_literal(ob,"<sup class='");
414 append_footnote_upc(ob, upc, 0);
415 blob_append_literal(ob,"noteref'><a href='");
416 BLOB_APPEND_URI(ob, ctx);
417 blob_appendf(ob,"#footnote%s' id='noteref%s'>%i</a></sup>",
418 pos, pos, iMark);
419 }
420 }else{ /* misreference */
@@ -427,19 +423,19 @@
423 sprintf(pos, "%s-%s", ctx->unique.c, l.c);
424 if(span && blob_size(span)) {
425 blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
426 blob_appendb(ob, span);
427 blob_trim(ob);
428 blob_append_literal(ob, "<sup class='noteref misref'><a href='");
429 BLOB_APPEND_URI(ob, ctx);
430 blob_appendf(ob, "#misreference%s'>misref</a></sup></span>", pos);
431 }else{
432 blob_trim(ob);
433 blob_append_literal(ob, "<sup class='noteref misref'><a href='");
434 BLOB_APPEND_URI(ob, ctx);
435 blob_appendf(ob, "#misreference%s' id='misref%s'>", pos, pos);
436 blob_append_literal(ob, "misref</a></sup>");
437 }
438 }
439 return 1;
440 }
441
@@ -456,11 +452,11 @@
452 /* expect BUGs if the following yields compiler warnings */
453
454 if( iMark < 0 ){ /* misreferences */
455 assert( iMark == -1 );
456 assert( nUsed );
457 blob_append_literal(ob,"<li class='fn-misreference'>"
458 "<sup class='fn-backrefs'>");
459 if( nUsed == 1 ){
460 blob_appendf(ob,"<a id='misreference%s-a' href='", unique);
461 BLOB_APPEND_URI(ob, ctx);
462 blob_appendf(ob,"#misref%s-a'>^</a>", unique);
@@ -471,13 +467,13 @@
467 const int c = i + (unsigned)'a';
468 blob_appendf(ob," <a id='misreference%s-%c' href='", unique,c);
469 BLOB_APPEND_URI(ob, ctx);
470 blob_appendf(ob,"#misref%s-%c'>%c</a>", unique,c, c);
471 }
472 if( i < nUsed ) blob_append_literal(ob," &hellip;");
473 }
474 blob_append_literal(ob,"</sup>\n<span>Misreference</span>");
475
476 }else if( iMark > 0 ){ /* regular, joined and overnested footnotes */
477 char pos[24];
478 int bJoin = 0;
479 #define _joined_footnote_indicator "<ul class='fn-joined'>"
@@ -490,25 +486,25 @@
486 blob_appendf(ob, "<li id='footnote%s' class='", pos);
487 if( nUsed ){
488 if( blob_size(text)>=_jfi_sz &&
489 !memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
490 bJoin = 1;
491 blob_append_literal(ob, "fn-joined ");
492 }
493 append_footnote_upc(ob, upc, 0);
494 }else{
495 blob_append_literal(ob, "fn-toodeep ");
496 }
497
498 if( nUsed <= 1 ){
499 blob_append_literal(ob, "fn-monoref'><sup class='fn-backrefs'>");
500 blob_appendf(ob,"<a id='footnote%s-a' href='", pos);
501 BLOB_APPEND_URI(ob, ctx);
502 blob_appendf(ob,"#noteref%s-a'>^</a>", pos);
503 }else{
504 int i;
505 blob_append_literal(ob, "fn-polyref'><sup class='fn-backrefs'>^");
506 for(i=0; i<nUsed && i<26; i++){
507 const int c = i + (unsigned)'a';
508 blob_appendf(ob," <a id='footnote%s-%c' href='", pos,c);
509 BLOB_APPEND_URI(ob, ctx);
510 blob_appendf(ob,"#noteref%s-%c'>%c</a>", pos,c, c);
@@ -519,27 +515,27 @@
515 const bitfield64_t l = to_base26(i,0);
516 blob_appendf(ob," <a id='footnote%s-%s' href='", pos, l.c);
517 BLOB_APPEND_URI(ob, ctx);
518 blob_appendf(ob,"#noteref%s-%s'>%s</a>", pos,l.c, l.c);
519 }
520 if( i < nUsed ) blob_append_literal(ob," &hellip;");
521 }
522 blob_append_literal(ob,"</sup>\n");
523 if( bJoin ){
524 blob_append_literal(ob,"<sup class='fn-joined'></sup><ul>");
525 blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
526 }else if( nUsed ){
527 append_footnote_upc(ob, upc, 1);
528 blob_appendb(ob, text);
529 }else{
530 blob_append_literal(ob,"<i></i>\n"
531 "<pre><code class='language-markdown'>");
532 if( blob_size(upc) ){
533 blob_appendb(ob, upc);
534 }
535 html_escape(ob, blob_buffer(text), blob_size(text));
536 blob_append_literal(ob,"</code></pre>");
537 }
538 #undef _joined_footnote_indicator
539 #undef _jfi_sz
540 }else{ /* a footnote was defined but wasn't referenced */
541 /* make.footnote_item() invocations should pass args accordingly */
@@ -546,30 +542,30 @@
542 const struct Blob * id = text-1;
543 assert( !nUsed );
544 assert( text );
545 assert( blob_size(text) );
546 assert( blob_size(id) );
547 blob_append_literal(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
548 html_escape(ob, blob_buffer(id), blob_size(id));
549 blob_append_literal(ob, "</code>&nbsp;]<i></i>\n"
550 "<pre><code class='language-markdown'>");
551 if( blob_size(upc) ){
552 blob_appendb(ob, upc);
553 }
554 html_escape(ob, blob_buffer(text), blob_size(text));
555 blob_append_literal(ob,"</code></pre>");
556 }
557 blob_append_literal(ob, "\n</li>\n");
558 }
559 static void html_footnotes(
560 struct Blob *ob, const struct Blob *items, void *opaque
561 ){
562 if( items && blob_size(items) ){
563 blob_append_literal(ob,
564 "\n<hr class='footnotes-separator'/>\n<ol class='footnotes'>\n");
565 blob_appendb(ob, items);
566 blob_append_literal(ob, "</ol>\n");
567 }
568 }
569
570 /* HTML span tags */
571
572

Keyboard Shortcuts

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