Fossil SCM
An extension of the now-merged code-in-pre branch to allow it to work on /artifact pages and such when the ln parameter is given. This branch is a proof of concept only, for demonstrating a point and experimentation, not to be merged. See [https://fossil-scm.org/forum/forumpost/0c4b91b48a | the forum discussion] for details.
Commit
a65834a727e02286605e52ba8e8ac448ecddabd68546e070390d9218dc087072
Parent
708696d88ae4935…
1 file changed
+19
-4
+19
-4
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -2051,14 +2051,19 @@ | ||
| 2051 | 2051 | ** zLn is the ?ln= parameter for the HTTP query. If there is an argument, |
| 2052 | 2052 | ** then highlight that line number and scroll to it once the page loads. |
| 2053 | 2053 | ** If there are two line numbers, highlight the range of lines. |
| 2054 | 2054 | ** Multiple ranges can be highlighed by adding additional line numbers |
| 2055 | 2055 | ** separated by a non-digit character (also not one of [-,.]). |
| 2056 | +** | |
| 2057 | +** zExt is the file name extension, if any. It is used to tag the output in | |
| 2058 | +** a way that allows CSS to attach styling to text blocks conditionally based | |
| 2059 | +** on file type. (e.g. code syntax highlighters) | |
| 2056 | 2060 | */ |
| 2057 | 2061 | void output_text_with_line_numbers( |
| 2058 | 2062 | const char *z, |
| 2059 | - const char *zLn | |
| 2063 | + const char *zLn, | |
| 2064 | + const char *zExt | |
| 2060 | 2065 | ){ |
| 2061 | 2066 | int iStart, iEnd; /* Start and end of region to highlight */ |
| 2062 | 2067 | int n = 0; /* Current line number */ |
| 2063 | 2068 | int i = 0; /* Loop index */ |
| 2064 | 2069 | int iTop = 0; /* Scroll so that this line is on top of screen. */ |
| @@ -2090,11 +2095,16 @@ | ||
| 2090 | 2095 | iEnd = db_column_int(&q, 1); |
| 2091 | 2096 | iTop = iStart - 15 + (iEnd-iStart)/4; |
| 2092 | 2097 | if( iTop>iStart - 2 ) iTop = iStart-2; |
| 2093 | 2098 | } |
| 2094 | 2099 | db_finalize(&q); |
| 2095 | - @ <pre> | |
| 2100 | + if( zExt && zExt[1] ){ | |
| 2101 | + @ <pre><code class="language-%s(zExt+1)"> | |
| 2102 | + } | |
| 2103 | + else { | |
| 2104 | + @ <pre> | |
| 2105 | + } | |
| 2096 | 2106 | while( z[0] ){ |
| 2097 | 2107 | n++; |
| 2098 | 2108 | db_prepare(&q, |
| 2099 | 2109 | "SELECT min(iStart), max(iEnd) FROM lnos" |
| 2100 | 2110 | " WHERE iStart <= %d AND iEnd >= %d", n, n); |
| @@ -2119,11 +2129,16 @@ | ||
| 2119 | 2129 | else cgi_append_content("\n", 1); |
| 2120 | 2130 | z += i; |
| 2121 | 2131 | if( z[0]=='\n' ) z++; |
| 2122 | 2132 | } |
| 2123 | 2133 | if( n<iEnd ) cgi_printf("</div>"); |
| 2124 | - @ </pre> | |
| 2134 | + if( zExt && zExt[1] ){ | |
| 2135 | + @ </code></pre> | |
| 2136 | + } | |
| 2137 | + else { | |
| 2138 | + @ </pre> | |
| 2139 | + } | |
| 2125 | 2140 | if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){ |
| 2126 | 2141 | style_load_one_js_file("scroll.js"); |
| 2127 | 2142 | } |
| 2128 | 2143 | } |
| 2129 | 2144 | |
| @@ -2347,11 +2362,11 @@ | ||
| 2347 | 2362 | " WHERE filename.fnid=mlink.fnid" |
| 2348 | 2363 | " AND mlink.fid=%d", |
| 2349 | 2364 | rid); |
| 2350 | 2365 | zExt = zFileName ? strrchr(zFileName, '.') : 0; |
| 2351 | 2366 | if( zLn ){ |
| 2352 | - output_text_with_line_numbers(z, zLn); | |
| 2367 | + output_text_with_line_numbers(z, zLn, zExt); | |
| 2353 | 2368 | }else if( zExt && zExt[1] ){ |
| 2354 | 2369 | @ <pre> |
| 2355 | 2370 | @ <code class="language-%s(zExt+1)">%h(z)</code> |
| 2356 | 2371 | @ </pre> |
| 2357 | 2372 | }else{ |
| 2358 | 2373 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -2051,14 +2051,19 @@ | |
| 2051 | ** zLn is the ?ln= parameter for the HTTP query. If there is an argument, |
| 2052 | ** then highlight that line number and scroll to it once the page loads. |
| 2053 | ** If there are two line numbers, highlight the range of lines. |
| 2054 | ** Multiple ranges can be highlighed by adding additional line numbers |
| 2055 | ** separated by a non-digit character (also not one of [-,.]). |
| 2056 | */ |
| 2057 | void output_text_with_line_numbers( |
| 2058 | const char *z, |
| 2059 | const char *zLn |
| 2060 | ){ |
| 2061 | int iStart, iEnd; /* Start and end of region to highlight */ |
| 2062 | int n = 0; /* Current line number */ |
| 2063 | int i = 0; /* Loop index */ |
| 2064 | int iTop = 0; /* Scroll so that this line is on top of screen. */ |
| @@ -2090,11 +2095,16 @@ | |
| 2090 | iEnd = db_column_int(&q, 1); |
| 2091 | iTop = iStart - 15 + (iEnd-iStart)/4; |
| 2092 | if( iTop>iStart - 2 ) iTop = iStart-2; |
| 2093 | } |
| 2094 | db_finalize(&q); |
| 2095 | @ <pre> |
| 2096 | while( z[0] ){ |
| 2097 | n++; |
| 2098 | db_prepare(&q, |
| 2099 | "SELECT min(iStart), max(iEnd) FROM lnos" |
| 2100 | " WHERE iStart <= %d AND iEnd >= %d", n, n); |
| @@ -2119,11 +2129,16 @@ | |
| 2119 | else cgi_append_content("\n", 1); |
| 2120 | z += i; |
| 2121 | if( z[0]=='\n' ) z++; |
| 2122 | } |
| 2123 | if( n<iEnd ) cgi_printf("</div>"); |
| 2124 | @ </pre> |
| 2125 | if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){ |
| 2126 | style_load_one_js_file("scroll.js"); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| @@ -2347,11 +2362,11 @@ | |
| 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 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -2051,14 +2051,19 @@ | |
| 2051 | ** zLn is the ?ln= parameter for the HTTP query. If there is an argument, |
| 2052 | ** then highlight that line number and scroll to it once the page loads. |
| 2053 | ** If there are two line numbers, highlight the range of lines. |
| 2054 | ** Multiple ranges can be highlighed by adding additional line numbers |
| 2055 | ** separated by a non-digit character (also not one of [-,.]). |
| 2056 | ** |
| 2057 | ** zExt is the file name extension, if any. It is used to tag the output in |
| 2058 | ** a way that allows CSS to attach styling to text blocks conditionally based |
| 2059 | ** on file type. (e.g. code syntax highlighters) |
| 2060 | */ |
| 2061 | void output_text_with_line_numbers( |
| 2062 | const char *z, |
| 2063 | const char *zLn, |
| 2064 | const char *zExt |
| 2065 | ){ |
| 2066 | int iStart, iEnd; /* Start and end of region to highlight */ |
| 2067 | int n = 0; /* Current line number */ |
| 2068 | int i = 0; /* Loop index */ |
| 2069 | int iTop = 0; /* Scroll so that this line is on top of screen. */ |
| @@ -2090,11 +2095,16 @@ | |
| 2095 | iEnd = db_column_int(&q, 1); |
| 2096 | iTop = iStart - 15 + (iEnd-iStart)/4; |
| 2097 | if( iTop>iStart - 2 ) iTop = iStart-2; |
| 2098 | } |
| 2099 | db_finalize(&q); |
| 2100 | if( zExt && zExt[1] ){ |
| 2101 | @ <pre><code class="language-%s(zExt+1)"> |
| 2102 | } |
| 2103 | else { |
| 2104 | @ <pre> |
| 2105 | } |
| 2106 | while( z[0] ){ |
| 2107 | n++; |
| 2108 | db_prepare(&q, |
| 2109 | "SELECT min(iStart), max(iEnd) FROM lnos" |
| 2110 | " WHERE iStart <= %d AND iEnd >= %d", n, n); |
| @@ -2119,11 +2129,16 @@ | |
| 2129 | else cgi_append_content("\n", 1); |
| 2130 | z += i; |
| 2131 | if( z[0]=='\n' ) z++; |
| 2132 | } |
| 2133 | if( n<iEnd ) cgi_printf("</div>"); |
| 2134 | if( zExt && zExt[1] ){ |
| 2135 | @ </code></pre> |
| 2136 | } |
| 2137 | else { |
| 2138 | @ </pre> |
| 2139 | } |
| 2140 | if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){ |
| 2141 | style_load_one_js_file("scroll.js"); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| @@ -2347,11 +2362,11 @@ | |
| 2362 | " WHERE filename.fnid=mlink.fnid" |
| 2363 | " AND mlink.fid=%d", |
| 2364 | rid); |
| 2365 | zExt = zFileName ? strrchr(zFileName, '.') : 0; |
| 2366 | if( zLn ){ |
| 2367 | output_text_with_line_numbers(z, zLn, zExt); |
| 2368 | }else if( zExt && zExt[1] ){ |
| 2369 | @ <pre> |
| 2370 | @ <code class="language-%s(zExt+1)">%h(z)</code> |
| 2371 | @ </pre> |
| 2372 | }else{ |
| 2373 |