331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
+
-
+
+
+
|
int flags,
void *opaque
){
BLOB_APPEND_LITERAL(ob, " <tr>\n");
BLOB_APPEND_BLOB(ob, cells);
BLOB_APPEND_LITERAL(ob, " </tr>\n");
}
static void append_footnote_upc(
struct Blob *ob,
const struct Blob *upc, /* token of user-provided classes */
int bHTML /* if true then render markup, otherwise just a list of classes */
){
const char *z = blob_buffer(upc);
int i, n = blob_size(upc);
if( n<3 ) return;
assert( z[0]=='.' && z[n-1] == ':' );
if( bHTML ){
BLOB_APPEND_LITERAL(ob, "<span class='fn-upc'>"
"<span class='fn-upcDot'>.</span>");
}
n = 0;
do{
z++;
if( *z!='.' && *z!=':' ){
assert( fossil_isalnum(*z) || *z=='-' );
n++;
continue;
}
assert( n );
if( bHTML ) BLOB_APPEND_LITERAL(ob, "<span class='");
BLOB_APPEND_LITERAL(ob, "fn-upc-");
for(i=-n; i<0; i++){
blob_append_char(ob, fossil_tolower(z[i]) );
}
if( bHTML ){
BLOB_APPEND_LITERAL(ob, "'>");
blob_append(ob, z-n, n);
BLOB_APPEND_LITERAL(ob, "</span>");
}else{
blob_append_char(ob, ' ');
}
n = 0;
if( bHTML ){
if( *z==':' ){
BLOB_APPEND_LITERAL(ob,"<span class='fn-upcColon'>:</span>");
}else{
BLOB_APPEND_LITERAL(ob,"<span class='fn-upcDot'>.</span>");
}
}
}while( *z != ':' );
if( bHTML ) BLOB_APPEND_LITERAL(ob,"</span>\n");
}
static int html_footnote_ref(
struct Blob *ob, const struct Blob *span, int iMark, int locus, void *opaque
struct Blob *ob, const struct Blob *span, const struct Blob *upc,
int iMark, int locus, void *opaque
){
const struct MarkdownToHtml* ctx = (struct MarkdownToHtml*)opaque;
const bitfield64_t l = to_base26(locus-1,0);
char pos[32];
memset(pos,0,32);
assert( locus > 0 );
/* expect BUGs if the following yields compiler warnings */
if( iMark > 0 ){ /* a regular reference to a footnote */
sprintf(pos, "%s-%i-%s", ctx->unique.c, iMark, l.c);
if(span && blob_size(span)) {
BLOB_APPEND_LITERAL(ob,"<span class='notescope' id='noteref");
BLOB_APPEND_LITERAL(ob,"<span class='");
append_footnote_upc(ob, upc, 0);
BLOB_APPEND_LITERAL(ob,"notescope' id='noteref");
blob_appendf(ob,"%s'>",pos);
BLOB_APPEND_BLOB(ob, span);
blob_trim(ob);
BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
BLOB_APPEND_URI(ob, ctx);
blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
}else{
blob_trim(ob);
BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
BLOB_APPEND_LITERAL(ob,"<sup class='");
append_footnote_upc(ob, upc, 0);
BLOB_APPEND_LITERAL(ob,"noteref'><a href='");
BLOB_APPEND_URI(ob, ctx);
blob_appendf(ob,"#footnote%s' id='noteref%s'>%i</a></sup>",
pos, pos, iMark);
}
}else{ /* misreference */
assert( iMark == -1 );
|
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
+
+
+
|
if( i < nUsed ) BLOB_APPEND_LITERAL(ob," …");
}
BLOB_APPEND_LITERAL(ob,"</sup>\n<span>Misreference</span>");
}else if( nUsed ){ /* a regular footnote */
char pos[24];
const char *join = "";
/* make.footnote_item() invocations should pass args accordingly */
const struct Blob * upc = text+1;
#define _joined_footnote_indicator "<ul class='fn-joined'>"
#define _jfi_sz (sizeof(_joined_footnote_indicator)-1)
assert( text );
assert( blob_size(text) );
if( blob_size(text)>=_jfi_sz &&
!memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
join = "fn-joined ";
}
memset(pos,0,24);
sprintf(pos, "%s-%i", unique, iMark);
blob_appendf(ob, "<li id='footnote%s' class='%s", pos, join);
append_footnote_upc(ob, upc, 0);
if( nUsed == 1 ){
BLOB_APPEND_LITERAL(ob, "fn-monoref'><sup class='fn-backrefs'>");
blob_appendf(ob,"<a id='footnote%s-a' href='", pos);
BLOB_APPEND_URI(ob, ctx);
blob_appendf(ob,"#noteref%s-a'>^</a>", pos);
}else{
|
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
+
|
blob_appendf(ob," <a id='footnote%s-%s' href='", pos, l.c);
BLOB_APPEND_URI(ob, ctx);
blob_appendf(ob,"#noteref%s-%s'>%s</a>", pos,l.c, l.c);
}
if( i < nUsed ) BLOB_APPEND_LITERAL(ob," …");
}
BLOB_APPEND_LITERAL(ob,"</sup>\n");
append_footnote_upc(ob, upc, 1);
if( join[0] ){
BLOB_APPEND_LITERAL(ob,"<sup class='fn-joined'></sup><ul>");
blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
}else{
BLOB_APPEND_BLOB(ob, text);
}
#undef _joined_footnote_indicator
|