| | @@ -1483,5 +1483,73 @@ |
| 1483 | 1483 | blob_zero(&out); |
| 1484 | 1484 | blob_read_from_file(&in, g.argv[2], ExtFILE); |
| 1485 | 1485 | markdown_to_html(&in, 0, &out); |
| 1486 | 1486 | blob_write_to_file(&out, "-"); |
| 1487 | 1487 | } |
| 1488 | + |
| 1489 | +/* |
| 1490 | +** Check to see if there exists a wiki page with a name zPrefix/zName. |
| 1491 | +** If there is, then render a <div class='section'>..</div> and |
| 1492 | +** return true. |
| 1493 | +** |
| 1494 | +** If there is no such wiki page, return false. |
| 1495 | +*/ |
| 1496 | +int wiki_render_associated( |
| 1497 | + const char *zPrefix, /* "branch", "tag", or "checkin" */ |
| 1498 | + const char *zName /* Name of the object */ |
| 1499 | +){ |
| 1500 | + int rid; |
| 1501 | + Manifest *pWiki; |
| 1502 | + rid = db_int(0, |
| 1503 | + "SELECT rid FROM tagxref" |
| 1504 | + " WHERE tagid=(SELECT tagid FROM tag WHERE tagname='wiki-%q/%q')" |
| 1505 | + " ORDER BY mtime DESC LIMIT 1", |
| 1506 | + zPrefix, zName |
| 1507 | + ); |
| 1508 | + if( rid==0 ) return 0; |
| 1509 | + pWiki = manifest_get(rid, CFTYPE_WIKI, 0); |
| 1510 | + if( pWiki==0 ) return 0; |
| 1511 | + if( fossil_strcmp(pWiki->zMimetype, "text/x-markdown")==0 ){ |
| 1512 | + Blob tail = BLOB_INITIALIZER; |
| 1513 | + Blob title = BLOB_INITIALIZER; |
| 1514 | + Blob markdown; |
| 1515 | + blob_init(&markdown, pWiki->zWiki, -1); |
| 1516 | + markdown_to_html(&markdown, &title, &tail); |
| 1517 | + if( blob_size(&title) ){ |
| 1518 | + @ <div class="section">%h(blob_str(&title))</div> |
| 1519 | + }else{ |
| 1520 | + @ <div class="section">About %s(zPrefix) %h(zName)<div> |
| 1521 | + } |
| 1522 | + @ <div class="wiki"> |
| 1523 | + convert_href_and_output(&tail); |
| 1524 | + @ </div> |
| 1525 | + blob_reset(&tail); |
| 1526 | + blob_reset(&title); |
| 1527 | + blob_reset(&markdown); |
| 1528 | + }else if( fossil_strcmp(pWiki->zMimetype, "text/plain")==0 ){ |
| 1529 | + @ <div class="section">About %s(zPrefix) %h(zName)</div> |
| 1530 | + @ <pre> |
| 1531 | + @ %h(pWiki->zWiki) |
| 1532 | + @ </pre> |
| 1533 | + }else{ |
| 1534 | + Blob tail = BLOB_INITIALIZER; |
| 1535 | + Blob title = BLOB_INITIALIZER; |
| 1536 | + Blob wiki; |
| 1537 | + blob_init(&wiki, pWiki->zWiki, -1); |
| 1538 | + if( wiki_find_title(&wiki, &title, &tail) ){ |
| 1539 | + @ <div class="section">%h(blob_str(&title))</div> |
| 1540 | + @ <div class="wiki"> |
| 1541 | + wiki_convert(&tail, 0, WIKI_BUTTONS); |
| 1542 | + @ </div> |
| 1543 | + }else{ |
| 1544 | + @ <div class="section">About %s(zPrefix) %h(zName)</div> |
| 1545 | + @ <div class="wiki"> |
| 1546 | + wiki_convert(&wiki, 0, WIKI_BUTTONS); |
| 1547 | + @ </div> |
| 1548 | + } |
| 1549 | + blob_reset(&tail); |
| 1550 | + blob_reset(&title); |
| 1551 | + blob_reset(&wiki); |
| 1552 | + } |
| 1553 | + manifest_destroy(pWiki); |
| 1554 | + return 1; |
| 1555 | +} |
| 1488 | 1556 | |