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.
Commit
155d07470d73b9c569689fb32640a8eaa4e290a9f6ccebbf47f273146b222486
Parent
a13082c284d12db…
1 file changed
+33
-3
+33
-3
| --- src/markdown_html.c | ||
| +++ src/markdown_html.c | ||
| @@ -328,18 +328,47 @@ | ||
| 328 | 328 | |
| 329 | 329 | /* |
| 330 | 330 | ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that |
| 331 | 331 | ** text and insert the result in place of the original. |
| 332 | 332 | */ |
| 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 | +){ | |
| 334 | 338 | int w = 0, h = 0; |
| 335 | 339 | char *zIn = fossil_strndup(zSrc, nSrc); |
| 336 | 340 | char *zOut = pikchr(zIn, "pikchr", 0, &w, &h); |
| 337 | 341 | fossil_free(zIn); |
| 338 | 342 | if( w>0 && h>0 ){ |
| 339 | 343 | 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); | |
| 341 | 370 | }else{ |
| 342 | 371 | blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut); |
| 343 | 372 | } |
| 344 | 373 | free(zOut); |
| 345 | 374 | } |
| @@ -382,11 +411,12 @@ | ||
| 382 | 411 | if( k==i ){ |
| 383 | 412 | blob_appendf(ob, "<pre><code>%#h</code></pre>", n-i, z+i); |
| 384 | 413 | }else{ |
| 385 | 414 | for(j=k+1; j<i && !fossil_isspace(z[j]); j++){} |
| 386 | 415 | 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); | |
| 388 | 418 | }else{ |
| 389 | 419 | blob_appendf(ob, "<pre><code class='language-%#h'>%#h</code></pre>", |
| 390 | 420 | j-k, z+k, n-i, z+i); |
| 391 | 421 | } |
| 392 | 422 | } |
| 393 | 423 |
| --- 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 |