Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Added optional filename parameter to output_text_with_line_numbers() so that it can add the language-X class to the CODE element. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | line-number-selection |
| Files: | files | file ages | folders |
| SHA3-256: |
0b3919f3e13218b0bad75a2a04e9d3cc |
| User & Date: | stephan 2020-08-14 12:21:22.076 |
Context
|
2020-08-14
| ||
| 12:28 | Corrected the JS-side recursive argument handling for the multiple-numbered-tables case. check-in: a54fa928e2 user: stephan tags: line-number-selection | |
| 12:21 | Added optional filename parameter to output_text_with_line_numbers() so that it can add the language-X class to the CODE element. check-in: 0b3919f3e1 user: stephan tags: line-number-selection | |
| 11:53 | Changes line-numbered output to make line numbers selectable, as discussed in [https://fossil-scm.org/forum/forumpost/dc3da10590]. A couple decisions are needed before deciding whether to merge. check-in: ec73edd4d0 user: stephan tags: line-number-selection | |
Changes
Changes to src/ajax.c.
| ︙ | ︙ | |||
128 129 130 131 132 133 134 |
case AJAX_RENDER_WIKI:
safe_html_context(DOCSRC_FILE);
wiki_render_by_mimetype(pContent, zMime);
break;
default:{
const char *zContent = blob_str(pContent);
if(AJAX_PREVIEW_LINE_NUMBERS & flags){
| | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
case AJAX_RENDER_WIKI:
safe_html_context(DOCSRC_FILE);
wiki_render_by_mimetype(pContent, zMime);
break;
default:{
const char *zContent = blob_str(pContent);
if(AJAX_PREVIEW_LINE_NUMBERS & flags){
output_text_with_line_numbers(zContent, blob_size(pContent),
zName, "on");
}else{
const char *zExt = strrchr(zName,'.');
if(zExt && zExt[1]){
CX("<pre><code class='language-%s'>%h</code></pre>",
zExt+1, zContent);
}else{
CX("<pre>%h</pre>", zContent);
|
| ︙ | ︙ |
Changes to src/attach.c.
| ︙ | ︙ | |||
615 616 617 618 619 620 621 |
blob_zero(&attach);
if( fShowContent ){
const char *z;
content_get(ridSrc, &attach);
blob_to_utf8_no_bom(&attach, 0);
z = blob_str(&attach);
if( zLn ){
| | | 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
blob_zero(&attach);
if( fShowContent ){
const char *z;
content_get(ridSrc, &attach);
blob_to_utf8_no_bom(&attach, 0);
z = blob_str(&attach);
if( zLn ){
output_text_with_line_numbers(z, blob_size(&attach), zName, zLn);
}else{
@ <pre>
@ %h(z)
@ </pre>
}
}else if( strncmp(zMime, "image/", 6)==0 ){
int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc);
|
| ︙ | ︙ |
Changes to src/file.c.
| ︙ | ︙ | |||
2395 2396 2397 2398 2399 2400 2401 |
if( dryRunFlag!=0 ){
fossil_print("dry-run: would have touched %d file(s)\n",
changeCount);
}else{
fossil_print("Touched %d file(s)\n", changeCount);
}
}
| > > > > > > > > > | 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 |
if( dryRunFlag!=0 ){
fossil_print("dry-run: would have touched %d file(s)\n",
changeCount);
}else{
fossil_print("Touched %d file(s)\n", changeCount);
}
}
/*
** If zFileName is not NULL and contains a '.', this returns a pointer
** to the position after the final '.', else it returns NULL.
*/
const char * file_extension(const char *zFileName){
const char * zExt = strrchr(zFileName, '.');
return zExt ? &zExt[1] : 0;
}
|
Changes to src/info.c.
| ︙ | ︙ | |||
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 |
return rid;
}
/*
** The "z" argument is a string that contains the text of a source
** code file and nZ is its length in bytes. This routine appends that
** text to the HTTP reply with line numbering.
**
** zLn is the ?ln= parameter for the HTTP query. If there is an argument,
** then highlight that line number and scroll to it once the page loads.
** If there are two line numbers, highlight the range of lines.
** Multiple ranges can be highlighed by adding additional line numbers
** separated by a non-digit character (also not one of [-,.]).
*/
void output_text_with_line_numbers(
const char *z,
int nZ,
const char *zLn
){
int iStart, iEnd; /* Start and end of region to highlight */
int n = 0; /* Current line number */
int i = 0; /* Loop index */
int iTop = 0; /* Scroll so that this line is on top of screen. */
int nLine = 0;
Stmt q;
iStart = iEnd = atoi(zLn);
db_multi_exec(
"CREATE TEMP TABLE lnos(iStart INTEGER PRIMARY KEY, iEnd INTEGER)");
if( iStart>0 ){
do{
| > > > > > > | 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 |
return rid;
}
/*
** The "z" argument is a string that contains the text of a source
** code file and nZ is its length in bytes. This routine appends that
** text to the HTTP reply with line numbering.
**
** zName is the content's file name, if any (it may be NULL). If that
** name contains a '.' then the part after the final '.' is used as
** the X part of a "language-X" CSS class on the generate CODE block.
**
** zLn is the ?ln= parameter for the HTTP query. If there is an argument,
** then highlight that line number and scroll to it once the page loads.
** If there are two line numbers, highlight the range of lines.
** Multiple ranges can be highlighed by adding additional line numbers
** separated by a non-digit character (also not one of [-,.]).
*/
void output_text_with_line_numbers(
const char *z,
int nZ,
const char *zName,
const char *zLn
){
int iStart, iEnd; /* Start and end of region to highlight */
int n = 0; /* Current line number */
int i = 0; /* Loop index */
int iTop = 0; /* Scroll so that this line is on top of screen. */
int nLine = 0;
const char *zExt = file_extension(zName);
Stmt q;
iStart = iEnd = atoi(zLn);
db_multi_exec(
"CREATE TEMP TABLE lnos(iStart INTEGER PRIMARY KEY, iEnd INTEGER)");
if( iStart>0 ){
do{
|
| ︙ | ︙ | |||
2064 2065 2066 2067 2068 2069 2070 |
}
db_finalize(&q);
CX("<table class='numbered-lines'><tbody><tr><td>");
count_lines(z, nZ, &nLine);
for(i=0; i < nLine; ++i){
CX("<span>%6d</span>", i+1);
}
| | > > > > > | 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 |
}
db_finalize(&q);
CX("<table class='numbered-lines'><tbody><tr><td>");
count_lines(z, nZ, &nLine);
for(i=0; i < nLine; ++i){
CX("<span>%6d</span>", i+1);
}
CX("</td><td><pre>");
if(zExt && *zExt){
CX("<code class='language-%h'>",zExt);
}else{
CX("<code>");
}
assert(!n);
while( z[0] ){
n++;
db_prepare(&q,
"SELECT min(iStart), max(iEnd) FROM lnos"
" WHERE iStart <= %d AND iEnd >= %d", n, n);
if( db_step(&q)==SQLITE_ROW ){
|
| ︙ | ︙ | |||
2121 2122 2123 2124 2125 2126 2127 |
zLn = g.argv[3];
}
db_find_and_open_repository(0,0);
zFilename = g.argv[2];
fossil_print("%s %s\n", zFilename, zLn);
blob_read_from_file(&content, zFilename, ExtFILE);
| | > | 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 |
zLn = g.argv[3];
}
db_find_and_open_repository(0,0);
zFilename = g.argv[2];
fossil_print("%s %s\n", zFilename, zLn);
blob_read_from_file(&content, zFilename, ExtFILE);
output_text_with_line_numbers(blob_str(&content), blob_size(&content),
zFilename, zLn);
blob_reset(&content);
fossil_print("%b\n", cgi_output_blob());
}
/*
** WEBPAGE: artifact
** WEBPAGE: file
|
| ︙ | ︙ | |||
2428 2429 2430 2431 2432 2433 2434 |
const char *z, *zFileName, *zExt;
z = blob_str(&content);
zFileName = db_text(0,
"SELECT name FROM mlink, filename"
" WHERE filename.fnid=mlink.fnid"
" AND mlink.fid=%d",
rid);
| | | > | 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 |
const char *z, *zFileName, *zExt;
z = blob_str(&content);
zFileName = db_text(0,
"SELECT name FROM mlink, filename"
" WHERE filename.fnid=mlink.fnid"
" AND mlink.fid=%d",
rid);
zExt = file_extension(zFileName);
if( zLn ){
output_text_with_line_numbers(z, blob_size(&content),
zFileName, zLn);
}else if( zExt && zExt[1] ){
@ <pre>
@ <code class="language-%s(zExt+1)">%h(z)</code>
@ </pre>
}else{
@ <pre>
@ %h(z)
|
| ︙ | ︙ |