Fossil SCM

Remerge the Wiki title search enhancement, after fixing it so that it does not disrupt check-in comment search.

drh 2024-01-09 17:18 trunk
Commit 9d9bf1abfb59ec6536fe47a2beec7c6e8adb4ed7456eab8fe8203d9b3418405b
1 file changed +34 -26
+34 -26
--- src/search.c
+++ src/search.c
@@ -1324,50 +1324,58 @@
13241324
13251325
/*
13261326
** This is a helper function for search_stext(). Writing into pOut
13271327
** the search text obtained from pIn according to zMimetype.
13281328
**
1329
+** If a title is not specified in zTitle (e.g. for wiki pages that do not
1330
+** include the title in the body), it is determined from the page content.
1331
+**
13291332
** The title of the document is the first line of text. All subsequent
13301333
** lines are the body. If the document has no title, the first line
13311334
** is blank.
13321335
*/
13331336
static void get_stext_by_mimetype(
13341337
Blob *pIn,
13351338
const char *zMimetype,
1339
+ const char *zTitle,
13361340
Blob *pOut
13371341
){
13381342
Blob html, title;
1343
+ Blob *pHtml = &html;
13391344
blob_init(&html, 0, 0);
1340
- blob_init(&title, 0, 0);
1345
+ if( zTitle==0 ){
1346
+ blob_init(&title, 0, 0);
1347
+ }else{
1348
+ blob_init(&title, zTitle, -1);
1349
+ }
13411350
if( zMimetype==0 ) zMimetype = "text/plain";
13421351
if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1343
- Blob tail;
1344
- blob_init(&tail, 0, 0);
1345
- if( wiki_find_title(pIn, &title, &tail) ){
1346
- blob_appendf(pOut, "%s\n", blob_str(&title));
1347
- wiki_convert(&tail, &html, 0);
1348
- blob_reset(&tail);
1349
- }else{
1350
- blob_append(pOut, "\n", 1);
1352
+ if( blob_size(&title) ){
13511353
wiki_convert(pIn, &html, 0);
1354
+ }else{
1355
+ Blob tail;
1356
+ blob_init(&tail, 0, 0);
1357
+ if( wiki_find_title(pIn, &title, &tail) ){
1358
+ blob_appendf(pOut, "%s\n", blob_str(&title));
1359
+ wiki_convert(&tail, &html, 0);
1360
+ blob_reset(&tail);
1361
+ }else{
1362
+ blob_append(pOut, "\n", 1);
1363
+ wiki_convert(pIn, &html, 0);
1364
+ }
13521365
}
13531366
html_to_plaintext(blob_str(&html), pOut);
13541367
}else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1355
- markdown_to_html(pIn, &title, &html);
1356
- if( blob_size(&title) ){
1357
- blob_appendf(pOut, "%s\n", blob_str(&title));
1358
- }else{
1359
- blob_append(pOut, "\n", 1);
1360
- }
1361
- html_to_plaintext(blob_str(&html), pOut);
1368
+ markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html);
13621369
}else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1363
- if( doc_is_embedded_html(pIn, &title) ){
1364
- blob_appendf(pOut, "%s\n", blob_str(&title));
1365
- }
1366
- html_to_plaintext(blob_str(pIn), pOut);
1370
+ if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title);
1371
+ pHtml = pIn;
1372
+ }
1373
+ blob_appendf(pOut, "%s\n", blob_str(&title));
1374
+ if( blob_size(pHtml) ){
1375
+ html_to_plaintext(blob_str(pHtml), pOut);
13671376
}else{
1368
- blob_append(pOut, "\n", 1);
13691377
blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
13701378
}
13711379
blob_reset(&html);
13721380
blob_reset(&title);
13731381
}
@@ -1400,11 +1408,11 @@
14001408
blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
14011409
}else{
14021410
Blob txt;
14031411
blob_init(&txt, db_column_text(pQuery,i), -1);
14041412
blob_appendf(pAccum, "%s: ", zColName);
1405
- get_stext_by_mimetype(&txt, zMime, pAccum);
1413
+ get_stext_by_mimetype(&txt, zMime, NULL, pAccum);
14061414
blob_append(pAccum, " |", 2);
14071415
blob_reset(&txt);
14081416
}
14091417
}
14101418
}
@@ -1439,11 +1447,11 @@
14391447
switch( cType ){
14401448
case 'd': { /* Documents */
14411449
Blob doc;
14421450
content_get(rid, &doc);
14431451
blob_to_utf8_no_bom(&doc, 0);
1444
- get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
1452
+ get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut);
14451453
blob_reset(&doc);
14461454
break;
14471455
}
14481456
case 'f': /* Forum messages */
14491457
case 'e': /* Tech Notes */
@@ -1461,11 +1469,11 @@
14611469
blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
14621470
}else{
14631471
blob_init(&wiki, pWiki->zWiki, -1);
14641472
}
14651473
get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1466
- pOut);
1474
+ cType=='w' ? pWiki->zWikiTitle : NULL, pOut);
14671475
blob_reset(&wiki);
14681476
manifest_destroy(pWiki);
14691477
break;
14701478
}
14711479
case 'c': { /* Check-in Comments */
@@ -1491,11 +1499,11 @@
14911499
db_column_blob(&q, 0, pOut);
14921500
}else{
14931501
Blob x;
14941502
blob_init(&x,0,0);
14951503
db_column_blob(&q, 0, &x);
1496
- get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
1504
+ get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut);
14971505
blob_reset(&x);
14981506
}
14991507
}
15001508
db_reset(&q);
15011509
break;
@@ -1602,11 +1610,11 @@
16021610
Blob in, out;
16031611
db_find_and_open_repository(0,0);
16041612
if( g.argc!=4 ) usage("FILENAME MIMETYPE");
16051613
blob_read_from_file(&in, g.argv[2], ExtFILE);
16061614
blob_init(&out, 0, 0);
1607
- get_stext_by_mimetype(&in, g.argv[3], &out);
1615
+ get_stext_by_mimetype(&in, g.argv[3], NULL, &out);
16081616
fossil_print("%s\n",blob_str(&out));
16091617
blob_reset(&in);
16101618
blob_reset(&out);
16111619
}
16121620
16131621
--- src/search.c
+++ src/search.c
@@ -1324,50 +1324,58 @@
1324
1325 /*
1326 ** This is a helper function for search_stext(). Writing into pOut
1327 ** the search text obtained from pIn according to zMimetype.
1328 **
 
 
 
1329 ** The title of the document is the first line of text. All subsequent
1330 ** lines are the body. If the document has no title, the first line
1331 ** is blank.
1332 */
1333 static void get_stext_by_mimetype(
1334 Blob *pIn,
1335 const char *zMimetype,
 
1336 Blob *pOut
1337 ){
1338 Blob html, title;
 
1339 blob_init(&html, 0, 0);
1340 blob_init(&title, 0, 0);
 
 
 
 
1341 if( zMimetype==0 ) zMimetype = "text/plain";
1342 if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1343 Blob tail;
1344 blob_init(&tail, 0, 0);
1345 if( wiki_find_title(pIn, &title, &tail) ){
1346 blob_appendf(pOut, "%s\n", blob_str(&title));
1347 wiki_convert(&tail, &html, 0);
1348 blob_reset(&tail);
1349 }else{
1350 blob_append(pOut, "\n", 1);
1351 wiki_convert(pIn, &html, 0);
 
 
 
 
 
 
 
 
 
 
 
1352 }
1353 html_to_plaintext(blob_str(&html), pOut);
1354 }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1355 markdown_to_html(pIn, &title, &html);
1356 if( blob_size(&title) ){
1357 blob_appendf(pOut, "%s\n", blob_str(&title));
1358 }else{
1359 blob_append(pOut, "\n", 1);
1360 }
1361 html_to_plaintext(blob_str(&html), pOut);
1362 }else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1363 if( doc_is_embedded_html(pIn, &title) ){
1364 blob_appendf(pOut, "%s\n", blob_str(&title));
1365 }
1366 html_to_plaintext(blob_str(pIn), pOut);
 
 
1367 }else{
1368 blob_append(pOut, "\n", 1);
1369 blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
1370 }
1371 blob_reset(&html);
1372 blob_reset(&title);
1373 }
@@ -1400,11 +1408,11 @@
1400 blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
1401 }else{
1402 Blob txt;
1403 blob_init(&txt, db_column_text(pQuery,i), -1);
1404 blob_appendf(pAccum, "%s: ", zColName);
1405 get_stext_by_mimetype(&txt, zMime, pAccum);
1406 blob_append(pAccum, " |", 2);
1407 blob_reset(&txt);
1408 }
1409 }
1410 }
@@ -1439,11 +1447,11 @@
1439 switch( cType ){
1440 case 'd': { /* Documents */
1441 Blob doc;
1442 content_get(rid, &doc);
1443 blob_to_utf8_no_bom(&doc, 0);
1444 get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
1445 blob_reset(&doc);
1446 break;
1447 }
1448 case 'f': /* Forum messages */
1449 case 'e': /* Tech Notes */
@@ -1461,11 +1469,11 @@
1461 blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
1462 }else{
1463 blob_init(&wiki, pWiki->zWiki, -1);
1464 }
1465 get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1466 pOut);
1467 blob_reset(&wiki);
1468 manifest_destroy(pWiki);
1469 break;
1470 }
1471 case 'c': { /* Check-in Comments */
@@ -1491,11 +1499,11 @@
1491 db_column_blob(&q, 0, pOut);
1492 }else{
1493 Blob x;
1494 blob_init(&x,0,0);
1495 db_column_blob(&q, 0, &x);
1496 get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
1497 blob_reset(&x);
1498 }
1499 }
1500 db_reset(&q);
1501 break;
@@ -1602,11 +1610,11 @@
1602 Blob in, out;
1603 db_find_and_open_repository(0,0);
1604 if( g.argc!=4 ) usage("FILENAME MIMETYPE");
1605 blob_read_from_file(&in, g.argv[2], ExtFILE);
1606 blob_init(&out, 0, 0);
1607 get_stext_by_mimetype(&in, g.argv[3], &out);
1608 fossil_print("%s\n",blob_str(&out));
1609 blob_reset(&in);
1610 blob_reset(&out);
1611 }
1612
1613
--- src/search.c
+++ src/search.c
@@ -1324,50 +1324,58 @@
1324
1325 /*
1326 ** This is a helper function for search_stext(). Writing into pOut
1327 ** the search text obtained from pIn according to zMimetype.
1328 **
1329 ** If a title is not specified in zTitle (e.g. for wiki pages that do not
1330 ** include the title in the body), it is determined from the page content.
1331 **
1332 ** The title of the document is the first line of text. All subsequent
1333 ** lines are the body. If the document has no title, the first line
1334 ** is blank.
1335 */
1336 static void get_stext_by_mimetype(
1337 Blob *pIn,
1338 const char *zMimetype,
1339 const char *zTitle,
1340 Blob *pOut
1341 ){
1342 Blob html, title;
1343 Blob *pHtml = &html;
1344 blob_init(&html, 0, 0);
1345 if( zTitle==0 ){
1346 blob_init(&title, 0, 0);
1347 }else{
1348 blob_init(&title, zTitle, -1);
1349 }
1350 if( zMimetype==0 ) zMimetype = "text/plain";
1351 if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1352 if( blob_size(&title) ){
 
 
 
 
 
 
 
1353 wiki_convert(pIn, &html, 0);
1354 }else{
1355 Blob tail;
1356 blob_init(&tail, 0, 0);
1357 if( wiki_find_title(pIn, &title, &tail) ){
1358 blob_appendf(pOut, "%s\n", blob_str(&title));
1359 wiki_convert(&tail, &html, 0);
1360 blob_reset(&tail);
1361 }else{
1362 blob_append(pOut, "\n", 1);
1363 wiki_convert(pIn, &html, 0);
1364 }
1365 }
1366 html_to_plaintext(blob_str(&html), pOut);
1367 }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1368 markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html);
 
 
 
 
 
 
1369 }else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1370 if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title);
1371 pHtml = pIn;
1372 }
1373 blob_appendf(pOut, "%s\n", blob_str(&title));
1374 if( blob_size(pHtml) ){
1375 html_to_plaintext(blob_str(pHtml), pOut);
1376 }else{
 
1377 blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
1378 }
1379 blob_reset(&html);
1380 blob_reset(&title);
1381 }
@@ -1400,11 +1408,11 @@
1408 blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
1409 }else{
1410 Blob txt;
1411 blob_init(&txt, db_column_text(pQuery,i), -1);
1412 blob_appendf(pAccum, "%s: ", zColName);
1413 get_stext_by_mimetype(&txt, zMime, NULL, pAccum);
1414 blob_append(pAccum, " |", 2);
1415 blob_reset(&txt);
1416 }
1417 }
1418 }
@@ -1439,11 +1447,11 @@
1447 switch( cType ){
1448 case 'd': { /* Documents */
1449 Blob doc;
1450 content_get(rid, &doc);
1451 blob_to_utf8_no_bom(&doc, 0);
1452 get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut);
1453 blob_reset(&doc);
1454 break;
1455 }
1456 case 'f': /* Forum messages */
1457 case 'e': /* Tech Notes */
@@ -1461,11 +1469,11 @@
1469 blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
1470 }else{
1471 blob_init(&wiki, pWiki->zWiki, -1);
1472 }
1473 get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1474 cType=='w' ? pWiki->zWikiTitle : NULL, pOut);
1475 blob_reset(&wiki);
1476 manifest_destroy(pWiki);
1477 break;
1478 }
1479 case 'c': { /* Check-in Comments */
@@ -1491,11 +1499,11 @@
1499 db_column_blob(&q, 0, pOut);
1500 }else{
1501 Blob x;
1502 blob_init(&x,0,0);
1503 db_column_blob(&q, 0, &x);
1504 get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut);
1505 blob_reset(&x);
1506 }
1507 }
1508 db_reset(&q);
1509 break;
@@ -1602,11 +1610,11 @@
1610 Blob in, out;
1611 db_find_and_open_repository(0,0);
1612 if( g.argc!=4 ) usage("FILENAME MIMETYPE");
1613 blob_read_from_file(&in, g.argv[2], ExtFILE);
1614 blob_init(&out, 0, 0);
1615 get_stext_by_mimetype(&in, g.argv[3], NULL, &out);
1616 fossil_print("%s\n",blob_str(&out));
1617 blob_reset(&in);
1618 blob_reset(&out);
1619 }
1620
1621

Keyboard Shortcuts

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