Fossil SCM

Added -html|-h flag to [/help?cmd=wiki|the wiki command], as discussed in [https://fossil-scm.org/forum/forumpost/7377c83dca|forumpost/7377c83dca], and cleaned up the command's help text and argument validation.

stephan 2020-01-28 02:53 trunk
Commit b23eb8331488435e423eefae2aee76071b3f1aed64ca4f16a43d1b8a0ea580c4
1 file changed +52 -17
+52 -17
--- src/wiki.c
+++ src/wiki.c
@@ -1224,11 +1224,11 @@
12241224
if( wrid==0 ){
12251225
if( !showAll ) continue;
12261226
@ <tr><td data-sortkey="%h(zSort)">\
12271227
@ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
12281228
}else{
1229
- @ <tr><td data=sortkey='%h(zSort)">\
1229
+ @ <tr><td data=sortkey="%h(zSort)">\
12301230
@ %z(href("%R/wiki?name=%T",zWName))%h(zWDisplayName)</a></td>
12311231
}
12321232
zAge = human_readable_age(rNow - rWmtime);
12331233
@ <td data-sortkey="%016llx(iMtime)">%s(zAge)</td>
12341234
fossil_free(zAge);
@@ -1364,19 +1364,25 @@
13641364
**
13651365
** Usage: %fossil wiki (export|create|commit|list) WikiName
13661366
**
13671367
** Run various subcommands to work with wiki entries or tech notes.
13681368
**
1369
-** %fossil wiki export PAGENAME ?FILE?
1370
-** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID
1369
+** %fossil wiki export ?OPTIONS? ?PAGENAME? ?FILE?
1370
+** %fossil wiki export ?OPTIONS? -t|--technote DATETIME|TECHNOTE-ID ?FILE?
13711371
**
13721372
** Sends the latest version of either a wiki page or of a tech note
13731373
** to the given file or standard output.
1374
-** If PAGENAME is provided, the wiki page will be output. For
1375
-** a tech note either DATETIME or TECHNOTE-ID must be specified. If
1376
-** DATETIME is used, the most recently modified tech note with that
1377
-** DATETIME will be sent.
1374
+**
1375
+** Options:
1376
+** If PAGENAME is provided, the named wiki page will be output.
1377
+** --technote|-t DATETIME|TECHNOTE-ID
1378
+** Specifies that a technote, rather than a wiki page,
1379
+** will be exported. If DATETIME is used, the most
1380
+** recently modified tech note with that DATETIME will
1381
+** output.
1382
+** -h|--html The body (only) is rendered in HTML form, without
1383
+** any page header/foot or HTML/BODY tag wrappers.
13781384
**
13791385
** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
13801386
**
13811387
** Create a new or commit changes to an existing wiki page or
13821388
** technote from FILE or from standard input. PAGENAME is the
@@ -1444,17 +1450,20 @@
14441450
const char *zFile; /* Name of the output file (0=stdout) */
14451451
const char *zETime; /* The name of the technote to export */
14461452
int rid; /* Artifact ID of the wiki page */
14471453
int i; /* Loop counter */
14481454
char *zBody = 0; /* Wiki page content */
1449
- Blob body; /* Wiki page content */
1455
+ Blob body = empty_blob; /* Wiki page content */
14501456
Manifest *pWiki = 0; /* Parsed wiki page content */
1457
+ int fHtml = 0; /* Export in HTML form */
14511458
1459
+ fHtml = find_option("html","h",0)!=0;
14521460
zETime = find_option("technote","t",1);
1461
+ verify_all_options();
14531462
if( !zETime ){
14541463
if( (g.argc!=4) && (g.argc!=5) ){
1455
- usage("export PAGENAME ?FILE?");
1464
+ usage("export ?-html? PAGENAME ?FILE?");
14561465
}
14571466
zPageName = g.argv[3];
14581467
rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
14591468
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
14601469
" ORDER BY x.mtime DESC LIMIT 1",
@@ -1467,11 +1476,12 @@
14671476
fossil_fatal("wiki page [%s] not found",zPageName);
14681477
}
14691478
zFile = (g.argc==4) ? "-" : g.argv[4];
14701479
}else{
14711480
if( (g.argc!=3) && (g.argc!=4) ){
1472
- usage("export ?FILE? --technote DATETIME|TECHNOTE-ID");
1481
+ usage("export ?-html? ?FILE? --technote "
1482
+ "DATETIME|TECHNOTE-ID");
14731483
}
14741484
rid = wiki_technote_to_rid(zETime);
14751485
if ( rid==-1 ){
14761486
fossil_fatal("ambiguous tech note id: %s", zETime);
14771487
}
@@ -1484,11 +1494,36 @@
14841494
zFile = (g.argc==3) ? "-" : g.argv[3];
14851495
}
14861496
for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
14871497
zBody[i] = 0;
14881498
blob_init(&body, zBody, -1);
1489
- blob_append(&body, "\n", 1);
1499
+ if(fHtml==0){
1500
+ blob_append(&body, "\n", 1);
1501
+ }else{
1502
+ Blob html = empty_blob; /* HTML-ized content */
1503
+ const char * zMimetype = wiki_filter_mimetypes(pWiki->zMimetype);
1504
+ if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){
1505
+ wiki_convert(&body,&html,0);
1506
+ }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
1507
+ markdown_to_html(&body,0,&html)
1508
+ /* TODO: add -HTML|-H flag to work like -html|-h but also
1509
+ ** add <html><body> tag wrappers around the output. The
1510
+ ** hurdle here is that the markdown converter resets its
1511
+ ** input blob before appending the output, which is
1512
+ ** different from wiki_convert() and htmlize_to_blob(), and
1513
+ ** precludes us simply appending the opening <html><body>
1514
+ ** part to the body
1515
+ */;
1516
+ }else if( fossil_strcmp(zMimetype, "text/plain")==0 ){
1517
+ htmlize_to_blob(&html,zBody,i);
1518
+ }else{
1519
+ fossil_fatal("Unsupported MIME type '%s' for wiki page '%s'.",
1520
+ zMimetype, pWiki->zWikiTitle );
1521
+ }
1522
+ blob_reset(&body);
1523
+ body = html /* transfer memory */;
1524
+ }
14901525
blob_write_to_file(&body, zFile);
14911526
blob_reset(&body);
14921527
manifest_destroy(pWiki);
14931528
return;
14941529
}else if( strncmp(g.argv[2],"commit",n)==0
@@ -1500,10 +1535,11 @@
15001535
const int isCreate = 'r'==g.argv[2][1] /* else "commit" */;
15011536
const char *zMimeType = find_option("mimetype", "M", 1);
15021537
const char *zETime = find_option("technote", "t", 1);
15031538
const char *zTags = find_option("technote-tags", NULL, 1);
15041539
const char *zClr = find_option("technote-bgcolor", NULL, 1);
1540
+ verify_all_options();
15051541
if( g.argc!=4 && g.argc!=5 ){
15061542
usage("commit|create PAGENAME ?FILE? [--mimetype TEXT-FORMAT]"
15071543
" [--technote DATETIME] [--technote-tags TAGS]"
15081544
" [--technote-bgcolor COLOR]");
15091545
}
@@ -1577,36 +1613,35 @@
15771613
}
15781614
}
15791615
manifest_destroy(pWiki);
15801616
blob_reset(&content);
15811617
}else if( strncmp(g.argv[2],"delete",n)==0 ){
1582
- if( g.argc!=5 ){
1618
+ if( g.argc!=4 ){
15831619
usage("delete PAGENAME");
15841620
}
15851621
fossil_fatal("delete not yet implemented.");
15861622
}else if(( strncmp(g.argv[2],"list",n)==0 )
15871623
|| ( strncmp(g.argv[2],"ls",n)==0 )){
15881624
Stmt q;
1589
- int showIds = 0;
1590
-
1591
- if ( !find_option("technote","t",0) ){
1625
+ const int fTechnote = find_option("technote","t",0)!=0;
1626
+ const int showIds = find_option("show-technote-ids","s",0)!=0;
1627
+ verify_all_options();
1628
+ if (fTechnote==0){
15921629
db_prepare(&q,
15931630
"SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
15941631
" ORDER BY lower(tagname) /*sort*/"
15951632
);
15961633
}else{
1597
- showIds = find_option("show-technote-ids","s",0)!=0;
15981634
db_prepare(&q,
15991635
"SELECT datetime(e.mtime), substr(t.tagname,7)"
16001636
" FROM event e, tag t"
16011637
" WHERE e.type='e'"
16021638
" AND e.tagid IS NOT NULL"
16031639
" AND t.tagid=e.tagid"
16041640
" ORDER BY e.mtime DESC /*sort*/"
16051641
);
16061642
}
1607
-
16081643
while( db_step(&q)==SQLITE_ROW ){
16091644
const char *zName = db_column_text(&q, 0);
16101645
if( showIds ){
16111646
const char *zUuid = db_column_text(&q, 1);
16121647
fossil_print("%s ",zUuid);
16131648
--- src/wiki.c
+++ src/wiki.c
@@ -1224,11 +1224,11 @@
1224 if( wrid==0 ){
1225 if( !showAll ) continue;
1226 @ <tr><td data-sortkey="%h(zSort)">\
1227 @ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
1228 }else{
1229 @ <tr><td data=sortkey='%h(zSort)">\
1230 @ %z(href("%R/wiki?name=%T",zWName))%h(zWDisplayName)</a></td>
1231 }
1232 zAge = human_readable_age(rNow - rWmtime);
1233 @ <td data-sortkey="%016llx(iMtime)">%s(zAge)</td>
1234 fossil_free(zAge);
@@ -1364,19 +1364,25 @@
1364 **
1365 ** Usage: %fossil wiki (export|create|commit|list) WikiName
1366 **
1367 ** Run various subcommands to work with wiki entries or tech notes.
1368 **
1369 ** %fossil wiki export PAGENAME ?FILE?
1370 ** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID
1371 **
1372 ** Sends the latest version of either a wiki page or of a tech note
1373 ** to the given file or standard output.
1374 ** If PAGENAME is provided, the wiki page will be output. For
1375 ** a tech note either DATETIME or TECHNOTE-ID must be specified. If
1376 ** DATETIME is used, the most recently modified tech note with that
1377 ** DATETIME will be sent.
 
 
 
 
 
 
1378 **
1379 ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
1380 **
1381 ** Create a new or commit changes to an existing wiki page or
1382 ** technote from FILE or from standard input. PAGENAME is the
@@ -1444,17 +1450,20 @@
1444 const char *zFile; /* Name of the output file (0=stdout) */
1445 const char *zETime; /* The name of the technote to export */
1446 int rid; /* Artifact ID of the wiki page */
1447 int i; /* Loop counter */
1448 char *zBody = 0; /* Wiki page content */
1449 Blob body; /* Wiki page content */
1450 Manifest *pWiki = 0; /* Parsed wiki page content */
 
1451
 
1452 zETime = find_option("technote","t",1);
 
1453 if( !zETime ){
1454 if( (g.argc!=4) && (g.argc!=5) ){
1455 usage("export PAGENAME ?FILE?");
1456 }
1457 zPageName = g.argv[3];
1458 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1459 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1460 " ORDER BY x.mtime DESC LIMIT 1",
@@ -1467,11 +1476,12 @@
1467 fossil_fatal("wiki page [%s] not found",zPageName);
1468 }
1469 zFile = (g.argc==4) ? "-" : g.argv[4];
1470 }else{
1471 if( (g.argc!=3) && (g.argc!=4) ){
1472 usage("export ?FILE? --technote DATETIME|TECHNOTE-ID");
 
1473 }
1474 rid = wiki_technote_to_rid(zETime);
1475 if ( rid==-1 ){
1476 fossil_fatal("ambiguous tech note id: %s", zETime);
1477 }
@@ -1484,11 +1494,36 @@
1484 zFile = (g.argc==3) ? "-" : g.argv[3];
1485 }
1486 for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
1487 zBody[i] = 0;
1488 blob_init(&body, zBody, -1);
1489 blob_append(&body, "\n", 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1490 blob_write_to_file(&body, zFile);
1491 blob_reset(&body);
1492 manifest_destroy(pWiki);
1493 return;
1494 }else if( strncmp(g.argv[2],"commit",n)==0
@@ -1500,10 +1535,11 @@
1500 const int isCreate = 'r'==g.argv[2][1] /* else "commit" */;
1501 const char *zMimeType = find_option("mimetype", "M", 1);
1502 const char *zETime = find_option("technote", "t", 1);
1503 const char *zTags = find_option("technote-tags", NULL, 1);
1504 const char *zClr = find_option("technote-bgcolor", NULL, 1);
 
1505 if( g.argc!=4 && g.argc!=5 ){
1506 usage("commit|create PAGENAME ?FILE? [--mimetype TEXT-FORMAT]"
1507 " [--technote DATETIME] [--technote-tags TAGS]"
1508 " [--technote-bgcolor COLOR]");
1509 }
@@ -1577,36 +1613,35 @@
1577 }
1578 }
1579 manifest_destroy(pWiki);
1580 blob_reset(&content);
1581 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1582 if( g.argc!=5 ){
1583 usage("delete PAGENAME");
1584 }
1585 fossil_fatal("delete not yet implemented.");
1586 }else if(( strncmp(g.argv[2],"list",n)==0 )
1587 || ( strncmp(g.argv[2],"ls",n)==0 )){
1588 Stmt q;
1589 int showIds = 0;
1590
1591 if ( !find_option("technote","t",0) ){
 
1592 db_prepare(&q,
1593 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1594 " ORDER BY lower(tagname) /*sort*/"
1595 );
1596 }else{
1597 showIds = find_option("show-technote-ids","s",0)!=0;
1598 db_prepare(&q,
1599 "SELECT datetime(e.mtime), substr(t.tagname,7)"
1600 " FROM event e, tag t"
1601 " WHERE e.type='e'"
1602 " AND e.tagid IS NOT NULL"
1603 " AND t.tagid=e.tagid"
1604 " ORDER BY e.mtime DESC /*sort*/"
1605 );
1606 }
1607
1608 while( db_step(&q)==SQLITE_ROW ){
1609 const char *zName = db_column_text(&q, 0);
1610 if( showIds ){
1611 const char *zUuid = db_column_text(&q, 1);
1612 fossil_print("%s ",zUuid);
1613
--- src/wiki.c
+++ src/wiki.c
@@ -1224,11 +1224,11 @@
1224 if( wrid==0 ){
1225 if( !showAll ) continue;
1226 @ <tr><td data-sortkey="%h(zSort)">\
1227 @ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
1228 }else{
1229 @ <tr><td data=sortkey="%h(zSort)">\
1230 @ %z(href("%R/wiki?name=%T",zWName))%h(zWDisplayName)</a></td>
1231 }
1232 zAge = human_readable_age(rNow - rWmtime);
1233 @ <td data-sortkey="%016llx(iMtime)">%s(zAge)</td>
1234 fossil_free(zAge);
@@ -1364,19 +1364,25 @@
1364 **
1365 ** Usage: %fossil wiki (export|create|commit|list) WikiName
1366 **
1367 ** Run various subcommands to work with wiki entries or tech notes.
1368 **
1369 ** %fossil wiki export ?OPTIONS? ?PAGENAME? ?FILE?
1370 ** %fossil wiki export ?OPTIONS? -t|--technote DATETIME|TECHNOTE-ID ?FILE?
1371 **
1372 ** Sends the latest version of either a wiki page or of a tech note
1373 ** to the given file or standard output.
1374 **
1375 ** Options:
1376 ** If PAGENAME is provided, the named wiki page will be output.
1377 ** --technote|-t DATETIME|TECHNOTE-ID
1378 ** Specifies that a technote, rather than a wiki page,
1379 ** will be exported. If DATETIME is used, the most
1380 ** recently modified tech note with that DATETIME will
1381 ** output.
1382 ** -h|--html The body (only) is rendered in HTML form, without
1383 ** any page header/foot or HTML/BODY tag wrappers.
1384 **
1385 ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
1386 **
1387 ** Create a new or commit changes to an existing wiki page or
1388 ** technote from FILE or from standard input. PAGENAME is the
@@ -1444,17 +1450,20 @@
1450 const char *zFile; /* Name of the output file (0=stdout) */
1451 const char *zETime; /* The name of the technote to export */
1452 int rid; /* Artifact ID of the wiki page */
1453 int i; /* Loop counter */
1454 char *zBody = 0; /* Wiki page content */
1455 Blob body = empty_blob; /* Wiki page content */
1456 Manifest *pWiki = 0; /* Parsed wiki page content */
1457 int fHtml = 0; /* Export in HTML form */
1458
1459 fHtml = find_option("html","h",0)!=0;
1460 zETime = find_option("technote","t",1);
1461 verify_all_options();
1462 if( !zETime ){
1463 if( (g.argc!=4) && (g.argc!=5) ){
1464 usage("export ?-html? PAGENAME ?FILE?");
1465 }
1466 zPageName = g.argv[3];
1467 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
1468 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1469 " ORDER BY x.mtime DESC LIMIT 1",
@@ -1467,11 +1476,12 @@
1476 fossil_fatal("wiki page [%s] not found",zPageName);
1477 }
1478 zFile = (g.argc==4) ? "-" : g.argv[4];
1479 }else{
1480 if( (g.argc!=3) && (g.argc!=4) ){
1481 usage("export ?-html? ?FILE? --technote "
1482 "DATETIME|TECHNOTE-ID");
1483 }
1484 rid = wiki_technote_to_rid(zETime);
1485 if ( rid==-1 ){
1486 fossil_fatal("ambiguous tech note id: %s", zETime);
1487 }
@@ -1484,11 +1494,36 @@
1494 zFile = (g.argc==3) ? "-" : g.argv[3];
1495 }
1496 for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
1497 zBody[i] = 0;
1498 blob_init(&body, zBody, -1);
1499 if(fHtml==0){
1500 blob_append(&body, "\n", 1);
1501 }else{
1502 Blob html = empty_blob; /* HTML-ized content */
1503 const char * zMimetype = wiki_filter_mimetypes(pWiki->zMimetype);
1504 if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){
1505 wiki_convert(&body,&html,0);
1506 }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
1507 markdown_to_html(&body,0,&html)
1508 /* TODO: add -HTML|-H flag to work like -html|-h but also
1509 ** add <html><body> tag wrappers around the output. The
1510 ** hurdle here is that the markdown converter resets its
1511 ** input blob before appending the output, which is
1512 ** different from wiki_convert() and htmlize_to_blob(), and
1513 ** precludes us simply appending the opening <html><body>
1514 ** part to the body
1515 */;
1516 }else if( fossil_strcmp(zMimetype, "text/plain")==0 ){
1517 htmlize_to_blob(&html,zBody,i);
1518 }else{
1519 fossil_fatal("Unsupported MIME type '%s' for wiki page '%s'.",
1520 zMimetype, pWiki->zWikiTitle );
1521 }
1522 blob_reset(&body);
1523 body = html /* transfer memory */;
1524 }
1525 blob_write_to_file(&body, zFile);
1526 blob_reset(&body);
1527 manifest_destroy(pWiki);
1528 return;
1529 }else if( strncmp(g.argv[2],"commit",n)==0
@@ -1500,10 +1535,11 @@
1535 const int isCreate = 'r'==g.argv[2][1] /* else "commit" */;
1536 const char *zMimeType = find_option("mimetype", "M", 1);
1537 const char *zETime = find_option("technote", "t", 1);
1538 const char *zTags = find_option("technote-tags", NULL, 1);
1539 const char *zClr = find_option("technote-bgcolor", NULL, 1);
1540 verify_all_options();
1541 if( g.argc!=4 && g.argc!=5 ){
1542 usage("commit|create PAGENAME ?FILE? [--mimetype TEXT-FORMAT]"
1543 " [--technote DATETIME] [--technote-tags TAGS]"
1544 " [--technote-bgcolor COLOR]");
1545 }
@@ -1577,36 +1613,35 @@
1613 }
1614 }
1615 manifest_destroy(pWiki);
1616 blob_reset(&content);
1617 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1618 if( g.argc!=4 ){
1619 usage("delete PAGENAME");
1620 }
1621 fossil_fatal("delete not yet implemented.");
1622 }else if(( strncmp(g.argv[2],"list",n)==0 )
1623 || ( strncmp(g.argv[2],"ls",n)==0 )){
1624 Stmt q;
1625 const int fTechnote = find_option("technote","t",0)!=0;
1626 const int showIds = find_option("show-technote-ids","s",0)!=0;
1627 verify_all_options();
1628 if (fTechnote==0){
1629 db_prepare(&q,
1630 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1631 " ORDER BY lower(tagname) /*sort*/"
1632 );
1633 }else{
 
1634 db_prepare(&q,
1635 "SELECT datetime(e.mtime), substr(t.tagname,7)"
1636 " FROM event e, tag t"
1637 " WHERE e.type='e'"
1638 " AND e.tagid IS NOT NULL"
1639 " AND t.tagid=e.tagid"
1640 " ORDER BY e.mtime DESC /*sort*/"
1641 );
1642 }
 
1643 while( db_step(&q)==SQLITE_ROW ){
1644 const char *zName = db_column_text(&q, 0);
1645 if( showIds ){
1646 const char *zUuid = db_column_text(&q, 1);
1647 fossil_print("%s ",zUuid);
1648

Keyboard Shortcuts

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