| | @@ -263,10 +263,48 @@ |
| 263 | 263 | if( zEnd[0] ) blob_append(pOut, zEnd, -1); |
| 264 | 264 | i = j; |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | + |
| 269 | +/* |
| 270 | +** Input string zIn starts with '['. If the content is a hyperlink of the |
| 271 | +** form [[...]] then return the index of the closing ']'. Otherwise return 0. |
| 272 | +*/ |
| 273 | +static int help_is_link(const char *z, int n){ |
| 274 | + int i; |
| 275 | + char c; |
| 276 | + if( n<5 ) return 0; |
| 277 | + if( z[1]!='[' ) return 0; |
| 278 | + for(i=3; i<n && (c = z[i])!=0; i++){ |
| 279 | + if( c==']' && z[i-1]==']' ) return i; |
| 280 | + } |
| 281 | + return 0; |
| 282 | +} |
| 283 | + |
| 284 | +/* |
| 285 | +** Append text to pOut, adding hyperlink markup for [...]. |
| 286 | +*/ |
| 287 | +static void appendLinked(Blob *pOut, const char *z, int n){ |
| 288 | + int i = 0; |
| 289 | + int j; |
| 290 | + while( i<n ){ |
| 291 | + if( z[i]=='[' && (j = help_is_link(z+i, n-i))>0 ){ |
| 292 | + if( i ) blob_append(pOut, z, i); |
| 293 | + z += i+2; |
| 294 | + n -= i+2; |
| 295 | + blob_appendf(pOut, "<a href='%R/help?cmd=%.*s'>%.*s</a>", |
| 296 | + j-3, z, j-3, z); |
| 297 | + z += j-1; |
| 298 | + n -= j-1; |
| 299 | + i = 0; |
| 300 | + }else{ |
| 301 | + i++; |
| 302 | + } |
| 303 | + } |
| 304 | + blob_append(pOut, z, i); |
| 305 | +} |
| 268 | 306 | |
| 269 | 307 | /* |
| 270 | 308 | ** Attempt to reformat plain-text help into HTML for display on a webpage. |
| 271 | 309 | ** |
| 272 | 310 | ** The HTML output is appended to Blob pHtml, which should already be |
| | @@ -394,11 +432,12 @@ |
| 394 | 432 | }else if( wantBR ){ |
| 395 | 433 | appendMixedFont(pHtml, zHelp+nIndent, i-nIndent); |
| 396 | 434 | blob_append(pHtml, "<br>\n", 5); |
| 397 | 435 | wantBR = 0; |
| 398 | 436 | }else{ |
| 399 | | - blob_appendf(pHtml, "%#h\n", i-nIndent, zHelp+nIndent); |
| 437 | + appendLinked(pHtml, zHelp+nIndent, i-nIndent); |
| 438 | + blob_append_char(pHtml, '\n'); |
| 400 | 439 | } |
| 401 | 440 | zHelp += i+1; |
| 402 | 441 | i = 0; |
| 403 | 442 | if( c==0 ) break; |
| 404 | 443 | } |
| | @@ -409,11 +448,11 @@ |
| 409 | 448 | |
| 410 | 449 | /* |
| 411 | 450 | ** Format help text for TTY display. |
| 412 | 451 | */ |
| 413 | 452 | static void help_to_text(const char *zHelp, Blob *pText){ |
| 414 | | - int i; |
| 453 | + int i, x; |
| 415 | 454 | char c; |
| 416 | 455 | for(i=0; (c = zHelp[i])!=0; i++){ |
| 417 | 456 | if( c=='%' && strncmp(zHelp+i,"%fossil",7)==0 ){ |
| 418 | 457 | if( i>0 ) blob_append(pText, zHelp, i); |
| 419 | 458 | blob_append(pText, "fossil", 6); |
| | @@ -426,10 +465,18 @@ |
| 426 | 465 | blob_append(pText, " ", 1); |
| 427 | 466 | zHelp += i+2; |
| 428 | 467 | i = -1; |
| 429 | 468 | continue; |
| 430 | 469 | } |
| 470 | + if( c=='[' && (x = help_is_link(zHelp+i, 100000))!=0 ){ |
| 471 | + if( i>0 ) blob_append(pText, zHelp, i); |
| 472 | + zHelp += i+2; |
| 473 | + blob_append(pText, zHelp, x-3); |
| 474 | + zHelp += x-1; |
| 475 | + i = -1; |
| 476 | + continue; |
| 477 | + } |
| 431 | 478 | } |
| 432 | 479 | if( i>0 ){ |
| 433 | 480 | blob_append(pText, zHelp, i); |
| 434 | 481 | } |
| 435 | 482 | } |
| | @@ -447,15 +494,17 @@ |
| 447 | 494 | ** -e|--everything Show all commands and pages. |
| 448 | 495 | ** -t|--test Include test- commands |
| 449 | 496 | ** -w|--www Show WWW pages. |
| 450 | 497 | ** -s|--settings Show settings. |
| 451 | 498 | ** -h|--html Transform output to HTML. |
| 499 | +** -r|--raw No output formatting. |
| 452 | 500 | */ |
| 453 | 501 | void test_all_help_cmd(void){ |
| 454 | 502 | int i; |
| 455 | 503 | int mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER; |
| 456 | 504 | int useHtml = find_option("html","h",0)!=0; |
| 505 | + int rawOut = find_option("raw","r",0)!=0; |
| 457 | 506 | |
| 458 | 507 | if( find_option("www","w",0) ){ |
| 459 | 508 | mask = CMDFLAG_WEBPAGE; |
| 460 | 509 | } |
| 461 | 510 | if( find_option("everything","e",0) ){ |
| | @@ -488,10 +537,13 @@ |
| 488 | 537 | blob_init(&html, 0, 0); |
| 489 | 538 | help_to_html(aCommand[i].zHelp, &html); |
| 490 | 539 | fossil_print("<h1>%h</h1>\n", aCommand[i].zName); |
| 491 | 540 | fossil_print("%s\n<hr>\n", blob_str(&html)); |
| 492 | 541 | blob_reset(&html); |
| 542 | + }else if( rawOut ){ |
| 543 | + fossil_print("# %s\n", aCommand[i].zName); |
| 544 | + fossil_print("%s\n\n", aCommand[i].zHelp); |
| 493 | 545 | }else{ |
| 494 | 546 | Blob txt; |
| 495 | 547 | blob_init(&txt, 0, 0); |
| 496 | 548 | help_to_text(aCommand[i].zHelp, &txt); |
| 497 | 549 | fossil_print("# %s\n", aCommand[i].zName); |
| 498 | 550 | |