Fossil SCM

Enable searching of wiki titles.

preben 2023-11-14 16:14 trunk merge
Commit a402dd2a888d6d7415070c64090eb2ba0e2490a7df564c29b1478c81054132b7
1 file changed +28 -26
+28 -26
--- src/search.c
+++ src/search.c
@@ -1229,50 +1229,52 @@
12291229
12301230
/*
12311231
** This is a helper function for search_stext(). Writing into pOut
12321232
** the search text obtained from pIn according to zMimetype.
12331233
**
1234
+** If a title is not specified in zTitle (e.g. for wiki pages that do not
1235
+** include the title in the body), it is determined from the page content.
1236
+**
12341237
** The title of the document is the first line of text. All subsequent
12351238
** lines are the body. If the document has no title, the first line
12361239
** is blank.
12371240
*/
12381241
static void get_stext_by_mimetype(
12391242
Blob *pIn,
12401243
const char *zMimetype,
1244
+ const char *zTitle,
12411245
Blob *pOut
12421246
){
12431247
Blob html, title;
1248
+ Blob *pHtml = &html;
12441249
blob_init(&html, 0, 0);
1245
- blob_init(&title, 0, 0);
1250
+ if( zTitle==0 ){
1251
+ blob_init(&title, 0, 0);
1252
+ }else{
1253
+ blob_init(&title, zTitle, -1);
1254
+ }
12461255
if( zMimetype==0 ) zMimetype = "text/plain";
12471256
if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1248
- Blob tail;
1249
- blob_init(&tail, 0, 0);
1250
- if( wiki_find_title(pIn, &title, &tail) ){
1251
- blob_appendf(pOut, "%s\n", blob_str(&title));
1257
+ if( blob_size(&title) ){
1258
+ wiki_convert(pIn, &html, 0);
1259
+ }else{
1260
+ Blob tail;
1261
+ blob_init(&tail, 0, 0);
1262
+ wiki_find_title(pIn, &title, &tail);
12521263
wiki_convert(&tail, &html, 0);
12531264
blob_reset(&tail);
1254
- }else{
1255
- blob_append(pOut, "\n", 1);
1256
- wiki_convert(pIn, &html, 0);
12571265
}
1258
- html_to_plaintext(blob_str(&html), pOut);
12591266
}else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1260
- markdown_to_html(pIn, &title, &html);
1261
- if( blob_size(&title) ){
1262
- blob_appendf(pOut, "%s\n", blob_str(&title));
1263
- }else{
1264
- blob_append(pOut, "\n", 1);
1265
- }
1266
- html_to_plaintext(blob_str(&html), pOut);
1267
+ markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html);
12671268
}else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1268
- if( doc_is_embedded_html(pIn, &title) ){
1269
- blob_appendf(pOut, "%s\n", blob_str(&title));
1270
- }
1271
- html_to_plaintext(blob_str(pIn), pOut);
1269
+ if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title);
1270
+ pHtml = pIn;
1271
+ }
1272
+ blob_appendf(pOut, "%s\n", blob_str(&title));
1273
+ if( blob_size(pHtml) ){
1274
+ html_to_plaintext(blob_str(pHtml), pOut);
12721275
}else{
1273
- blob_append(pOut, "\n", 1);
12741276
blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
12751277
}
12761278
blob_reset(&html);
12771279
blob_reset(&title);
12781280
}
@@ -1305,11 +1307,11 @@
13051307
blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
13061308
}else{
13071309
Blob txt;
13081310
blob_init(&txt, db_column_text(pQuery,i), -1);
13091311
blob_appendf(pAccum, "%s: ", zColName);
1310
- get_stext_by_mimetype(&txt, zMime, pAccum);
1312
+ get_stext_by_mimetype(&txt, zMime, NULL, pAccum);
13111313
blob_append(pAccum, " |", 2);
13121314
blob_reset(&txt);
13131315
}
13141316
}
13151317
}
@@ -1344,11 +1346,11 @@
13441346
switch( cType ){
13451347
case 'd': { /* Documents */
13461348
Blob doc;
13471349
content_get(rid, &doc);
13481350
blob_to_utf8_no_bom(&doc, 0);
1349
- get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
1351
+ get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut);
13501352
blob_reset(&doc);
13511353
break;
13521354
}
13531355
case 'f': /* Forum messages */
13541356
case 'e': /* Tech Notes */
@@ -1366,11 +1368,11 @@
13661368
blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
13671369
}else{
13681370
blob_init(&wiki, pWiki->zWiki, -1);
13691371
}
13701372
get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1371
- pOut);
1373
+ cType=='w' ? pWiki->zWikiTitle : NULL, pOut);
13721374
blob_reset(&wiki);
13731375
manifest_destroy(pWiki);
13741376
break;
13751377
}
13761378
case 'c': { /* Check-in Comments */
@@ -1396,11 +1398,11 @@
13961398
db_column_blob(&q, 0, pOut);
13971399
}else{
13981400
Blob x;
13991401
blob_init(&x,0,0);
14001402
db_column_blob(&q, 0, &x);
1401
- get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
1403
+ get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut);
14021404
blob_reset(&x);
14031405
}
14041406
}
14051407
db_reset(&q);
14061408
break;
@@ -1507,11 +1509,11 @@
15071509
Blob in, out;
15081510
db_find_and_open_repository(0,0);
15091511
if( g.argc!=4 ) usage("FILENAME MIMETYPE");
15101512
blob_read_from_file(&in, g.argv[2], ExtFILE);
15111513
blob_init(&out, 0, 0);
1512
- get_stext_by_mimetype(&in, g.argv[3], &out);
1514
+ get_stext_by_mimetype(&in, g.argv[3], NULL, &out);
15131515
fossil_print("%s\n",blob_str(&out));
15141516
blob_reset(&in);
15151517
blob_reset(&out);
15161518
}
15171519
15181520
--- src/search.c
+++ src/search.c
@@ -1229,50 +1229,52 @@
1229
1230 /*
1231 ** This is a helper function for search_stext(). Writing into pOut
1232 ** the search text obtained from pIn according to zMimetype.
1233 **
 
 
 
1234 ** The title of the document is the first line of text. All subsequent
1235 ** lines are the body. If the document has no title, the first line
1236 ** is blank.
1237 */
1238 static void get_stext_by_mimetype(
1239 Blob *pIn,
1240 const char *zMimetype,
 
1241 Blob *pOut
1242 ){
1243 Blob html, title;
 
1244 blob_init(&html, 0, 0);
1245 blob_init(&title, 0, 0);
 
 
 
 
1246 if( zMimetype==0 ) zMimetype = "text/plain";
1247 if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1248 Blob tail;
1249 blob_init(&tail, 0, 0);
1250 if( wiki_find_title(pIn, &title, &tail) ){
1251 blob_appendf(pOut, "%s\n", blob_str(&title));
 
 
1252 wiki_convert(&tail, &html, 0);
1253 blob_reset(&tail);
1254 }else{
1255 blob_append(pOut, "\n", 1);
1256 wiki_convert(pIn, &html, 0);
1257 }
1258 html_to_plaintext(blob_str(&html), pOut);
1259 }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1260 markdown_to_html(pIn, &title, &html);
1261 if( blob_size(&title) ){
1262 blob_appendf(pOut, "%s\n", blob_str(&title));
1263 }else{
1264 blob_append(pOut, "\n", 1);
1265 }
1266 html_to_plaintext(blob_str(&html), pOut);
1267 }else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1268 if( doc_is_embedded_html(pIn, &title) ){
1269 blob_appendf(pOut, "%s\n", blob_str(&title));
1270 }
1271 html_to_plaintext(blob_str(pIn), pOut);
 
 
1272 }else{
1273 blob_append(pOut, "\n", 1);
1274 blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
1275 }
1276 blob_reset(&html);
1277 blob_reset(&title);
1278 }
@@ -1305,11 +1307,11 @@
1305 blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
1306 }else{
1307 Blob txt;
1308 blob_init(&txt, db_column_text(pQuery,i), -1);
1309 blob_appendf(pAccum, "%s: ", zColName);
1310 get_stext_by_mimetype(&txt, zMime, pAccum);
1311 blob_append(pAccum, " |", 2);
1312 blob_reset(&txt);
1313 }
1314 }
1315 }
@@ -1344,11 +1346,11 @@
1344 switch( cType ){
1345 case 'd': { /* Documents */
1346 Blob doc;
1347 content_get(rid, &doc);
1348 blob_to_utf8_no_bom(&doc, 0);
1349 get_stext_by_mimetype(&doc, mimetype_from_name(zName), pOut);
1350 blob_reset(&doc);
1351 break;
1352 }
1353 case 'f': /* Forum messages */
1354 case 'e': /* Tech Notes */
@@ -1366,11 +1368,11 @@
1366 blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
1367 }else{
1368 blob_init(&wiki, pWiki->zWiki, -1);
1369 }
1370 get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1371 pOut);
1372 blob_reset(&wiki);
1373 manifest_destroy(pWiki);
1374 break;
1375 }
1376 case 'c': { /* Check-in Comments */
@@ -1396,11 +1398,11 @@
1396 db_column_blob(&q, 0, pOut);
1397 }else{
1398 Blob x;
1399 blob_init(&x,0,0);
1400 db_column_blob(&q, 0, &x);
1401 get_stext_by_mimetype(&x, "text/x-fossil-wiki", pOut);
1402 blob_reset(&x);
1403 }
1404 }
1405 db_reset(&q);
1406 break;
@@ -1507,11 +1509,11 @@
1507 Blob in, out;
1508 db_find_and_open_repository(0,0);
1509 if( g.argc!=4 ) usage("FILENAME MIMETYPE");
1510 blob_read_from_file(&in, g.argv[2], ExtFILE);
1511 blob_init(&out, 0, 0);
1512 get_stext_by_mimetype(&in, g.argv[3], &out);
1513 fossil_print("%s\n",blob_str(&out));
1514 blob_reset(&in);
1515 blob_reset(&out);
1516 }
1517
1518
--- src/search.c
+++ src/search.c
@@ -1229,50 +1229,52 @@
1229
1230 /*
1231 ** This is a helper function for search_stext(). Writing into pOut
1232 ** the search text obtained from pIn according to zMimetype.
1233 **
1234 ** If a title is not specified in zTitle (e.g. for wiki pages that do not
1235 ** include the title in the body), it is determined from the page content.
1236 **
1237 ** The title of the document is the first line of text. All subsequent
1238 ** lines are the body. If the document has no title, the first line
1239 ** is blank.
1240 */
1241 static void get_stext_by_mimetype(
1242 Blob *pIn,
1243 const char *zMimetype,
1244 const char *zTitle,
1245 Blob *pOut
1246 ){
1247 Blob html, title;
1248 Blob *pHtml = &html;
1249 blob_init(&html, 0, 0);
1250 if( zTitle==0 ){
1251 blob_init(&title, 0, 0);
1252 }else{
1253 blob_init(&title, zTitle, -1);
1254 }
1255 if( zMimetype==0 ) zMimetype = "text/plain";
1256 if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")==0 ){
1257 if( blob_size(&title) ){
1258 wiki_convert(pIn, &html, 0);
1259 }else{
1260 Blob tail;
1261 blob_init(&tail, 0, 0);
1262 wiki_find_title(pIn, &title, &tail);
1263 wiki_convert(&tail, &html, 0);
1264 blob_reset(&tail);
 
 
 
1265 }
 
1266 }else if( fossil_strcmp(zMimetype,"text/x-markdown")==0 ){
1267 markdown_to_html(pIn, blob_size(&title) ? NULL : &title, &html);
 
 
 
 
 
 
1268 }else if( fossil_strcmp(zMimetype,"text/html")==0 ){
1269 if( blob_size(&title)==0 ) doc_is_embedded_html(pIn, &title);
1270 pHtml = pIn;
1271 }
1272 blob_appendf(pOut, "%s\n", blob_str(&title));
1273 if( blob_size(pHtml) ){
1274 html_to_plaintext(blob_str(pHtml), pOut);
1275 }else{
 
1276 blob_append(pOut, blob_buffer(pIn), blob_size(pIn));
1277 }
1278 blob_reset(&html);
1279 blob_reset(&title);
1280 }
@@ -1305,11 +1307,11 @@
1307 blob_appendf(pAccum, "%s: %s |\n", zColName, db_column_text(pQuery,i));
1308 }else{
1309 Blob txt;
1310 blob_init(&txt, db_column_text(pQuery,i), -1);
1311 blob_appendf(pAccum, "%s: ", zColName);
1312 get_stext_by_mimetype(&txt, zMime, NULL, pAccum);
1313 blob_append(pAccum, " |", 2);
1314 blob_reset(&txt);
1315 }
1316 }
1317 }
@@ -1344,11 +1346,11 @@
1346 switch( cType ){
1347 case 'd': { /* Documents */
1348 Blob doc;
1349 content_get(rid, &doc);
1350 blob_to_utf8_no_bom(&doc, 0);
1351 get_stext_by_mimetype(&doc, mimetype_from_name(zName), NULL, pOut);
1352 blob_reset(&doc);
1353 break;
1354 }
1355 case 'f': /* Forum messages */
1356 case 'e': /* Tech Notes */
@@ -1366,11 +1368,11 @@
1368 blob_appendf(&wiki, "From %s:\n\n%s", pWiki->zUser, pWiki->zWiki);
1369 }else{
1370 blob_init(&wiki, pWiki->zWiki, -1);
1371 }
1372 get_stext_by_mimetype(&wiki, wiki_filter_mimetypes(pWiki->zMimetype),
1373 cType=='w' ? pWiki->zWikiTitle : NULL, pOut);
1374 blob_reset(&wiki);
1375 manifest_destroy(pWiki);
1376 break;
1377 }
1378 case 'c': { /* Check-in Comments */
@@ -1396,11 +1398,11 @@
1398 db_column_blob(&q, 0, pOut);
1399 }else{
1400 Blob x;
1401 blob_init(&x,0,0);
1402 db_column_blob(&q, 0, &x);
1403 get_stext_by_mimetype(&x, "text/x-fossil-wiki", NULL, pOut);
1404 blob_reset(&x);
1405 }
1406 }
1407 db_reset(&q);
1408 break;
@@ -1507,11 +1509,11 @@
1509 Blob in, out;
1510 db_find_and_open_repository(0,0);
1511 if( g.argc!=4 ) usage("FILENAME MIMETYPE");
1512 blob_read_from_file(&in, g.argv[2], ExtFILE);
1513 blob_init(&out, 0, 0);
1514 get_stext_by_mimetype(&in, g.argv[3], NULL, &out);
1515 fossil_print("%s\n",blob_str(&out));
1516 blob_reset(&in);
1517 blob_reset(&out);
1518 }
1519
1520

Keyboard Shortcuts

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