Fossil SCM
Adds syntax-hl boolean option, fixes file extension retrieval. The addition of the syntax-hl boolean allows fossil to detect at the behest of the user that a syntax highlighting system that will handle line numbering is being used in cooperation with fossil such that fossil need not try to do line numbering, selection, highlighting, etc, itself. The file extension retrieval is now done with no use of extra or one off queries.
Commit
6ead94abf8e10ee3c215b5e7d98db865a4e453fb2615819e46c963987b6f5b34
Parent
f6e635308c0c03f…
2 files changed
+5
+6
-13
M
src/db.c
+5
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -3600,10 +3600,15 @@ | ||
| 3600 | 3600 | ** A shell command used to launch your preferred |
| 3601 | 3601 | ** web browser when given a URL as an argument. |
| 3602 | 3602 | ** Defaults to "start" on windows, "open" on Mac, |
| 3603 | 3603 | ** and "firefox" on Unix. |
| 3604 | 3604 | */ |
| 3605 | +/* | |
| 3606 | +** SETTING: syntax-hl boolean default=off | |
| 3607 | +** This is a boolean set such that themes can use TH1 code | |
| 3608 | +** to detect if they should enable syntax highlighting. | |
| 3609 | +*/ | |
| 3605 | 3610 | |
| 3606 | 3611 | /* |
| 3607 | 3612 | ** Look up a control setting by its name. Return a pointer to the Setting |
| 3608 | 3613 | ** object, or NULL if there is no such setting. |
| 3609 | 3614 | ** |
| 3610 | 3615 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -3600,10 +3600,15 @@ | |
| 3600 | ** A shell command used to launch your preferred |
| 3601 | ** web browser when given a URL as an argument. |
| 3602 | ** Defaults to "start" on windows, "open" on Mac, |
| 3603 | ** and "firefox" on Unix. |
| 3604 | */ |
| 3605 | |
| 3606 | /* |
| 3607 | ** Look up a control setting by its name. Return a pointer to the Setting |
| 3608 | ** object, or NULL if there is no such setting. |
| 3609 | ** |
| 3610 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -3600,10 +3600,15 @@ | |
| 3600 | ** A shell command used to launch your preferred |
| 3601 | ** web browser when given a URL as an argument. |
| 3602 | ** Defaults to "start" on windows, "open" on Mac, |
| 3603 | ** and "firefox" on Unix. |
| 3604 | */ |
| 3605 | /* |
| 3606 | ** SETTING: syntax-hl boolean default=off |
| 3607 | ** This is a boolean set such that themes can use TH1 code |
| 3608 | ** to detect if they should enable syntax highlighting. |
| 3609 | */ |
| 3610 | |
| 3611 | /* |
| 3612 | ** Look up a control setting by its name. Return a pointer to the Setting |
| 3613 | ** object, or NULL if there is no such setting. |
| 3614 | ** |
| 3615 |
+6
-13
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -2338,27 +2338,20 @@ | ||
| 2338 | 2338 | } |
| 2339 | 2339 | blob_to_utf8_no_bom(&content, 0); |
| 2340 | 2340 | zMime = mimetype_from_content(&content); |
| 2341 | 2341 | @ <blockquote> |
| 2342 | 2342 | if( zMime==0 ){ |
| 2343 | - const char *z, *zFileName, *zExt; | |
| 2343 | + const char *z, *zFileName, *zExt, *zLanguage, *tmp; | |
| 2344 | 2344 | z = blob_str(&content); |
| 2345 | - zFileName = db_text(0, | |
| 2346 | - "SELECT name FROM mlink, filename" | |
| 2347 | - " WHERE filename.fnid=mlink.fnid" | |
| 2348 | - " AND mlink.fid=%d", | |
| 2349 | - rid); | |
| 2350 | - zExt = zFileName ? strrchr(zFileName, '.') : 0; | |
| 2351 | - if( zLn ){ | |
| 2345 | + zFileName = blob_str(&downloadName); | |
| 2346 | + zExt = (tmp = strrchr(zFileName, '.')) == NULL ? "" : tmp+1; | |
| 2347 | + zLanguage = strrchr(zFileName, '.') == NULL ? "" : "language-"; | |
| 2348 | + if( zLn && (db_get_boolean("syntax-hl", 0) == 0) ) { | |
| 2352 | 2349 | output_text_with_line_numbers(z, zLn); |
| 2353 | - }else if( zExt && zExt[1] ){ | |
| 2354 | - @ <pre> | |
| 2355 | - @ <code class="language-%s(zExt+1)">%h(z)</code> | |
| 2356 | - @ </pre> | |
| 2357 | 2350 | }else{ |
| 2358 | 2351 | @ <pre> |
| 2359 | - @ %h(z) | |
| 2352 | + @ <code class="%s(zLanguage)%s(zExt)">%h(z)</code> | |
| 2360 | 2353 | @ </pre> |
| 2361 | 2354 | } |
| 2362 | 2355 | }else if( strncmp(zMime, "image/", 6)==0 ){ |
| 2363 | 2356 | @ <p>(file is %d(blob_size(&content)) bytes of image data)</i></p> |
| 2364 | 2357 | @ <p><img src="%R/raw/%s(zUuid)?m=%s(zMime)"></p> |
| 2365 | 2358 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -2338,27 +2338,20 @@ | |
| 2338 | } |
| 2339 | blob_to_utf8_no_bom(&content, 0); |
| 2340 | zMime = mimetype_from_content(&content); |
| 2341 | @ <blockquote> |
| 2342 | if( zMime==0 ){ |
| 2343 | const char *z, *zFileName, *zExt; |
| 2344 | z = blob_str(&content); |
| 2345 | zFileName = db_text(0, |
| 2346 | "SELECT name FROM mlink, filename" |
| 2347 | " WHERE filename.fnid=mlink.fnid" |
| 2348 | " AND mlink.fid=%d", |
| 2349 | rid); |
| 2350 | zExt = zFileName ? strrchr(zFileName, '.') : 0; |
| 2351 | if( zLn ){ |
| 2352 | output_text_with_line_numbers(z, zLn); |
| 2353 | }else if( zExt && zExt[1] ){ |
| 2354 | @ <pre> |
| 2355 | @ <code class="language-%s(zExt+1)">%h(z)</code> |
| 2356 | @ </pre> |
| 2357 | }else{ |
| 2358 | @ <pre> |
| 2359 | @ %h(z) |
| 2360 | @ </pre> |
| 2361 | } |
| 2362 | }else if( strncmp(zMime, "image/", 6)==0 ){ |
| 2363 | @ <p>(file is %d(blob_size(&content)) bytes of image data)</i></p> |
| 2364 | @ <p><img src="%R/raw/%s(zUuid)?m=%s(zMime)"></p> |
| 2365 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -2338,27 +2338,20 @@ | |
| 2338 | } |
| 2339 | blob_to_utf8_no_bom(&content, 0); |
| 2340 | zMime = mimetype_from_content(&content); |
| 2341 | @ <blockquote> |
| 2342 | if( zMime==0 ){ |
| 2343 | const char *z, *zFileName, *zExt, *zLanguage, *tmp; |
| 2344 | z = blob_str(&content); |
| 2345 | zFileName = blob_str(&downloadName); |
| 2346 | zExt = (tmp = strrchr(zFileName, '.')) == NULL ? "" : tmp+1; |
| 2347 | zLanguage = strrchr(zFileName, '.') == NULL ? "" : "language-"; |
| 2348 | if( zLn && (db_get_boolean("syntax-hl", 0) == 0) ) { |
| 2349 | output_text_with_line_numbers(z, zLn); |
| 2350 | }else{ |
| 2351 | @ <pre> |
| 2352 | @ <code class="%s(zLanguage)%s(zExt)">%h(z)</code> |
| 2353 | @ </pre> |
| 2354 | } |
| 2355 | }else if( strncmp(zMime, "image/", 6)==0 ){ |
| 2356 | @ <p>(file is %d(blob_size(&content)) bytes of image data)</i></p> |
| 2357 | @ <p><img src="%R/raw/%s(zUuid)?m=%s(zMime)"></p> |
| 2358 |