Fossil SCM

Parse the "info string" for Pikchr blocks for one of "center", "indent", "float-left", or "float-right" and add a <div> to accomplished the desired display mode.

drh 2020-09-09 17:10 trunk
Commit 155d07470d73b9c569689fb32640a8eaa4e290a9f6ccebbf47f273146b222486
1 file changed +33 -3
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -328,18 +328,47 @@
328328
329329
/*
330330
** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
331331
** text and insert the result in place of the original.
332332
*/
333
-static void fenced_code_pikchr_to_html(Blob *ob, const char *zSrc, int nSrc){
333
+static void fenced_code_pikchr_to_html(
334
+ Blob *ob, /* Write the generated SVG here */
335
+ const char *zSrc, int nSrc, /* The Pikchr source text */
336
+ const char *zArg, int nArg /* Addition arguments */
337
+){
334338
int w = 0, h = 0;
335339
char *zIn = fossil_strndup(zSrc, nSrc);
336340
char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
337341
fossil_free(zIn);
338342
if( w>0 && h>0 ){
339343
const char *zNonce = safe_html_nonce(1);
340
- blob_appendf(ob, "%s\n%s%s", zNonce, zOut, zNonce);
344
+ char *zCss = 0;
345
+ blob_append(ob, zNonce, -1);
346
+ blob_append_char(ob, '\n');
347
+ while( nArg>0 && zCss==0 ){
348
+ int i;
349
+ for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
350
+ if( i==6 && strncmp(zArg, "center", 6)==0 ){
351
+ zCss = mprintf("display:block;margin:auto;width:%dpx;", w);
352
+ }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
353
+ zCss = fossil_strdup("margin-left:4em;");
354
+ }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
355
+ zCss = mprintf("float:left;width:%d;padding=4em;",w);
356
+ }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
357
+ zCss = mprintf("float:right;width:%d;padding=4em;",w);
358
+ }
359
+ while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
360
+ zArg += i;
361
+ nArg -= i;
362
+ }
363
+ if( zCss ) blob_appendf(ob, "<div style='%s'>\n", zCss);
364
+ blob_append(ob, zOut, -1);
365
+ if( zCss ){
366
+ blob_appendf(ob, "</div>\n");
367
+ fossil_free(zCss);
368
+ }
369
+ blob_appendf(ob, "%s\n", zNonce);
341370
}else{
342371
blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
343372
}
344373
free(zOut);
345374
}
@@ -382,11 +411,12 @@
382411
if( k==i ){
383412
blob_appendf(ob, "<pre><code>%#h</code></pre>", n-i, z+i);
384413
}else{
385414
for(j=k+1; j<i && !fossil_isspace(z[j]); j++){}
386415
if( j-k==6 && strncmp(z+k,"pikchr",6)==0 ){
387
- fenced_code_pikchr_to_html(ob, z+i, n-i);
416
+ while( j<i && fossil_isspace(z[j]) ){ j++; }
417
+ fenced_code_pikchr_to_html(ob, z+i, n-i, z+j, i-j);
388418
}else{
389419
blob_appendf(ob, "<pre><code class='language-%#h'>%#h</code></pre>",
390420
j-k, z+k, n-i, z+i);
391421
}
392422
}
393423
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -328,18 +328,47 @@
328
329 /*
330 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
331 ** text and insert the result in place of the original.
332 */
333 static void fenced_code_pikchr_to_html(Blob *ob, const char *zSrc, int nSrc){
 
 
 
 
334 int w = 0, h = 0;
335 char *zIn = fossil_strndup(zSrc, nSrc);
336 char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
337 fossil_free(zIn);
338 if( w>0 && h>0 ){
339 const char *zNonce = safe_html_nonce(1);
340 blob_appendf(ob, "%s\n%s%s", zNonce, zOut, zNonce);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341 }else{
342 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
343 }
344 free(zOut);
345 }
@@ -382,11 +411,12 @@
382 if( k==i ){
383 blob_appendf(ob, "<pre><code>%#h</code></pre>", n-i, z+i);
384 }else{
385 for(j=k+1; j<i && !fossil_isspace(z[j]); j++){}
386 if( j-k==6 && strncmp(z+k,"pikchr",6)==0 ){
387 fenced_code_pikchr_to_html(ob, z+i, n-i);
 
388 }else{
389 blob_appendf(ob, "<pre><code class='language-%#h'>%#h</code></pre>",
390 j-k, z+k, n-i, z+i);
391 }
392 }
393
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -328,18 +328,47 @@
328
329 /*
330 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
331 ** text and insert the result in place of the original.
332 */
333 static void fenced_code_pikchr_to_html(
334 Blob *ob, /* Write the generated SVG here */
335 const char *zSrc, int nSrc, /* The Pikchr source text */
336 const char *zArg, int nArg /* Addition arguments */
337 ){
338 int w = 0, h = 0;
339 char *zIn = fossil_strndup(zSrc, nSrc);
340 char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
341 fossil_free(zIn);
342 if( w>0 && h>0 ){
343 const char *zNonce = safe_html_nonce(1);
344 char *zCss = 0;
345 blob_append(ob, zNonce, -1);
346 blob_append_char(ob, '\n');
347 while( nArg>0 && zCss==0 ){
348 int i;
349 for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
350 if( i==6 && strncmp(zArg, "center", 6)==0 ){
351 zCss = mprintf("display:block;margin:auto;width:%dpx;", w);
352 }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
353 zCss = fossil_strdup("margin-left:4em;");
354 }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
355 zCss = mprintf("float:left;width:%d;padding=4em;",w);
356 }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
357 zCss = mprintf("float:right;width:%d;padding=4em;",w);
358 }
359 while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
360 zArg += i;
361 nArg -= i;
362 }
363 if( zCss ) blob_appendf(ob, "<div style='%s'>\n", zCss);
364 blob_append(ob, zOut, -1);
365 if( zCss ){
366 blob_appendf(ob, "</div>\n");
367 fossil_free(zCss);
368 }
369 blob_appendf(ob, "%s\n", zNonce);
370 }else{
371 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
372 }
373 free(zOut);
374 }
@@ -382,11 +411,12 @@
411 if( k==i ){
412 blob_appendf(ob, "<pre><code>%#h</code></pre>", n-i, z+i);
413 }else{
414 for(j=k+1; j<i && !fossil_isspace(z[j]); j++){}
415 if( j-k==6 && strncmp(z+k,"pikchr",6)==0 ){
416 while( j<i && fossil_isspace(z[j]) ){ j++; }
417 fenced_code_pikchr_to_html(ob, z+i, n-i, z+j, i-j);
418 }else{
419 blob_appendf(ob, "<pre><code class='language-%#h'>%#h</code></pre>",
420 j-k, z+k, n-i, z+i);
421 }
422 }
423

Keyboard Shortcuts

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