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.

wyoung 2019-09-05 01:33 trunk
Commit a65834a727e02286605e52ba8e8ac448ecddabd68546e070390d9218dc087072
1 file changed +19 -4
+19 -4
--- src/info.c
+++ src/info.c
@@ -2051,14 +2051,19 @@
20512051
** zLn is the ?ln= parameter for the HTTP query. If there is an argument,
20522052
** then highlight that line number and scroll to it once the page loads.
20532053
** If there are two line numbers, highlight the range of lines.
20542054
** Multiple ranges can be highlighed by adding additional line numbers
20552055
** 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)
20562060
*/
20572061
void output_text_with_line_numbers(
20582062
const char *z,
2059
- const char *zLn
2063
+ const char *zLn,
2064
+ const char *zExt
20602065
){
20612066
int iStart, iEnd; /* Start and end of region to highlight */
20622067
int n = 0; /* Current line number */
20632068
int i = 0; /* Loop index */
20642069
int iTop = 0; /* Scroll so that this line is on top of screen. */
@@ -2090,11 +2095,16 @@
20902095
iEnd = db_column_int(&q, 1);
20912096
iTop = iStart - 15 + (iEnd-iStart)/4;
20922097
if( iTop>iStart - 2 ) iTop = iStart-2;
20932098
}
20942099
db_finalize(&q);
2095
- @ <pre>
2100
+ if( zExt && zExt[1] ){
2101
+ @ <pre><code class="language-%s(zExt+1)">
2102
+ }
2103
+ else {
2104
+ @ <pre>
2105
+ }
20962106
while( z[0] ){
20972107
n++;
20982108
db_prepare(&q,
20992109
"SELECT min(iStart), max(iEnd) FROM lnos"
21002110
" WHERE iStart <= %d AND iEnd >= %d", n, n);
@@ -2119,11 +2129,16 @@
21192129
else cgi_append_content("\n", 1);
21202130
z += i;
21212131
if( z[0]=='\n' ) z++;
21222132
}
21232133
if( n<iEnd ) cgi_printf("</div>");
2124
- @ </pre>
2134
+ if( zExt && zExt[1] ){
2135
+ @ </code></pre>
2136
+ }
2137
+ else {
2138
+ @ </pre>
2139
+ }
21252140
if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
21262141
style_load_one_js_file("scroll.js");
21272142
}
21282143
}
21292144
@@ -2347,11 +2362,11 @@
23472362
" WHERE filename.fnid=mlink.fnid"
23482363
" AND mlink.fid=%d",
23492364
rid);
23502365
zExt = zFileName ? strrchr(zFileName, '.') : 0;
23512366
if( zLn ){
2352
- output_text_with_line_numbers(z, zLn);
2367
+ output_text_with_line_numbers(z, zLn, zExt);
23532368
}else if( zExt && zExt[1] ){
23542369
@ <pre>
23552370
@ <code class="language-%s(zExt+1)">%h(z)</code>
23562371
@ </pre>
23572372
}else{
23582373
--- 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

Keyboard Shortcuts

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