@@ -180,7 +180,7 @@ end -- text_output
180
180
local P, R, S, C, Cc, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Ct
181
181
local TAG = (P"<" * P"/"^-1 * R("AZ", "az")^1 * P"/"^-1 * P">")/tag_output
182
182
local NOT_TAG = ((1 - lpeg.P"<")^0/text_output)
183
- local HTML = (NOT_TAG * TAG * NOT_TAG)^0
183
+ local HTML = (NOT_TAG * TAG * NOT_TAG)^1 + NOT_TAG
184
184
185
185
-- show a help item with a coloured heading, and coloured text
186
186
@@ -211,7 +211,6 @@ end -- show_item
211
211
212
212
-- normal functions
213
213
local function show_functions_help (row)
214
-
215
214
NoteHr ()
216
215
show_item (HEADINGCOLOUR, "Function", NAMECOLOUR, row.name)
217
216
show_item (HEADINGCOLOUR, "Summary", SUMMARYCOLOUR, row.summary)
@@ -220,27 +219,22 @@ local function show_functions_help (row)
220
219
show_item (HEADINGCOLOUR, "Return Value", RETURNVALUE, row.return_value)
221
220
show_item (HEADINGCOLOUR, "Lua Example", CODECOLOUR, row.lua_example)
222
221
show_item (HEADINGCOLOUR, "Lua Notes", NOTESCOLOUR, row.lua_notes)
223
-
224
222
end -- show_functions_help
225
223
226
224
-- general help (major topics)
227
225
local function show_general_help (row)
228
-
229
226
NoteHr ()
230
227
show_item (NOTESCOLOUR, "", NAMECOLOUR, row.title)
231
- show_item (HEADINGCOLOUR, "Summary", SUMMARYCOLOUR, row.description, true)
232
-
228
+ show_item (HEADINGCOLOUR, "Summary", SUMMARYCOLOUR, row.description, true) -- HTML codes
233
229
end -- show_general_help
234
230
235
231
-- lua functions
236
232
local function show_lua_functions_help (row)
237
-
238
233
NoteHr ()
239
234
show_item (HEADINGCOLOUR, "Lua", NAMECOLOUR, row.name)
240
235
show_item (HEADINGCOLOUR, "Summary", SUMMARYCOLOUR, row.summary)
241
236
show_item (HEADINGCOLOUR, "Prototype", PROTOTYPECOLOUR, row.prototype)
242
- show_item (HEADINGCOLOUR, "Description", DESCRIPTIONCOLOUR, row.description, true)
243
-
237
+ show_item (HEADINGCOLOUR, "Description", DESCRIPTIONCOLOUR, row.description, true) -- HTML codes
244
238
end -- show_lua_functions_help
245
239
246
240
@@ -306,20 +300,8 @@ function general_help (search_string, want_snippet)
306
300
-- show snippet
307
301
308
302
if want_snippet then
309
-
310
- -- fix up snippet ...
311
- -- get rid of imbedded tags
312
- snippet = snippet:gsub ("</?%a+/?>", "")
313
- -- get rid of partial leading tags (eg. b>)
314
- snippet = snippet:gsub ("^ %.%.%. /?%a-/?>", "")
315
- -- get rid of partial closing tags (eg. <b)
316
- snippet = snippet:gsub ("</?%a-/? %.%.%. $", "")
317
-
318
- -- convert entities ...
319
- snippet = snippet:gsub ("&%a-;", entities)
320
-
321
- -- phew! now show it
322
- AnsiNote (RESET .. snippet)
303
+ -- get rid of newlines, and multiple spaces
304
+ AnsiNote (RESET .. string.gsub (snippet, "%s+", " "))
323
305
print ""
324
306
end -- if snippet wanted
325
307
@@ -406,6 +388,20 @@ function help_find_snippet (name, line, wildcards)
406
388
general_help (wildcards [1], true)
407
389
end -- help_find_snippet
408
390
391
+ local function fix_description (s)
392
+ if not s then
393
+ return ""
394
+ end -- if
395
+
396
+ -- get rid of tags
397
+ s = s:gsub ("</?%a+/?>", "")
398
+
399
+ -- convert entities ...
400
+ s = s:gsub ("&%a-;", entities)
401
+
402
+ return s
403
+ end -- fix_description
404
+
409
405
function OnPluginInstall ()
410
406
-- open database on disk
411
407
@@ -438,41 +434,82 @@ function OnPluginInstall ()
438
434
if not fts4 then
439
435
local start = utils.timer ()
440
436
ColourNote ("cyan", "", "Creating help database full-text lookup tables ...")
441
- assert (db:execute[[
442
- BEGIN TRANSACTION;
443
-
444
- DROP TABLE IF EXISTS commands_lookup;
445
- CREATE VIRTUAL TABLE commands_lookup USING FTS4(name, short_description, description);
446
- INSERT INTO commands_lookup (name, short_description, description)
447
- SELECT command_name, short_description, description FROM commands;
448
-
449
- DROP TABLE IF EXISTS dialogs_lookup;
450
- CREATE VIRTUAL TABLE dialogs_lookup USING FTS4(name, title, description);
451
- INSERT INTO dialogs_lookup (name, title, description)
452
- SELECT dialog_name, title, description FROM dialogs;
437
+
438
+ -- START
439
+ assert (db:execute [[
440
+ BEGIN TRANSACTION;
441
+ DROP TABLE IF EXISTS commands_lookup;
442
+ DROP TABLE IF EXISTS dialogs_lookup;
443
+ DROP TABLE IF EXISTS functions_lookup;
444
+ DROP TABLE IF EXISTS general_doc_lookup;
445
+ DROP TABLE IF EXISTS errors_lookup;
446
+ DROP TABLE IF EXISTS lua_functions_lookup;
447
+ ]])
448
+
449
+ -- COMMANDS
450
+ assert (db:execute "CREATE VIRTUAL TABLE commands_lookup USING FTS4(name, summary, description)")
451
+
452
+ -- fix up HTML stuff
453
+ for row in db:nrows("SELECT command_name, short_description, description FROM commands") do
454
+ assert (db:execute (string.format ([[
455
+ INSERT INTO commands_lookup (name, summary, description)
456
+ VALUES (%s, %s, %s)]],
457
+ fixsql (row.command_name),
458
+ fixsql (row.short_description),
459
+ fixsql (fix_description (row.description)))))
460
+ end -- for
453
461
454
- DROP TABLE IF EXISTS functions_lookup;
455
- CREATE VIRTUAL TABLE functions_lookup USING FTS4(name, summary, description, lua_example, lua_notes);
456
- INSERT INTO functions_lookup (name, summary, description, lua_example, lua_notes)
457
- SELECT name, summary, description, lua_example, lua_notes FROM functions;
462
+ -- DIALOGS
463
+ assert (db:execute "CREATE VIRTUAL TABLE dialogs_lookup USING FTS4(name, summary, description)")
464
+
465
+ -- fix up HTML stuff
466
+ for row in db:nrows("SELECT dialog_name, title, description FROM dialogs") do
467
+ assert (db:execute (string.format ([[
468
+ INSERT INTO dialogs_lookup (name, summary, description)
469
+ VALUES (%s, %s, %s)]],
470
+ fixsql (row.dialog_name),
471
+ fixsql (row.title),
472
+ fixsql (fix_description (row.description)))))
473
+ end -- for
458
474
459
- DROP TABLE IF EXISTS general_doc_lookup;
460
- CREATE VIRTUAL TABLE general_doc_lookup USING FTS4(name, title , description);
461
- INSERT INTO general_doc_lookup (name, title , description)
462
- SELECT doc_name, title , description FROM general_doc;
475
+ -- WORLD FUNCTIONS
476
+ assert (db:execute " CREATE VIRTUAL TABLE functions_lookup USING FTS4(name, summary , description, lua_example, lua_notes)")
477
+ assert (db:execute [[ INSERT INTO functions_lookup (name, summary , description, lua_example, lua_notes )
478
+ SELECT name, summary , description, lua_example, lua_notes FROM functions]])
463
479
464
- DROP TABLE IF EXISTS errors_lookup;
465
- CREATE VIRTUAL TABLE errors_lookup USING FTS4(name, error_code, description);
466
- INSERT INTO errors_lookup (name, error_code, description)
467
- SELECT error_name, error_code, meaning FROM errors;
480
+ -- GENERAL TOPICS
481
+ assert (db:execute "CREATE VIRTUAL TABLE general_doc_lookup USING FTS4(name, summary, description)")
482
+
483
+ -- fix up HTML stuff
484
+ for row in db:nrows("SELECT doc_name, title, description FROM general_doc") do
485
+ assert (db:execute (string.format ([[
486
+ INSERT INTO general_doc_lookup (name, summary, description)
487
+ VALUES (%s, %s, %s)]],
488
+ fixsql (row.doc_name),
489
+ fixsql (row.title),
490
+ fixsql (fix_description (row.description)))))
491
+ end -- for
468
492
469
- DROP TABLE IF EXISTS lua_functions_lookup;
470
- CREATE VIRTUAL TABLE lua_functions_lookup USING FTS4(name, summary , description);
471
- INSERT INTO lua_functions_lookup (name, summary , description)
472
- SELECT name, summary, description FROM lua_functions;
493
+ -- ERRORS
494
+ assert (db:execute " CREATE VIRTUAL TABLE errors_lookup USING FTS4(name, error_code , description)")
495
+ assert (db:execute [[ INSERT INTO errors_lookup (name, error_code , description)
496
+ SELECT error_name, error_code, meaning FROM errors ]])
473
497
474
- COMMIT;
475
- ]])
498
+ -- LUA FUNCTIONS
499
+ assert (db:execute "CREATE VIRTUAL TABLE lua_functions_lookup USING FTS4(name, summary, description)")
500
+
501
+ -- fix up HTML stuff
502
+ for row in db:nrows("SELECT name, summary, description FROM lua_functions") do
503
+ assert (db:execute (string.format ([[
504
+ INSERT INTO lua_functions_lookup (name, summary, description)
505
+ VALUES (%s, %s, %s)]],
506
+ fixsql (row.name),
507
+ fixsql (row.summary),
508
+ fixsql (fix_description (row.description)))))
509
+ end -- for
510
+
511
+ -- DONE
512
+ assert (db:execute "COMMIT;")
476
513
ColourNote ("cyan", "", string.format ("Done. Took %0.3f seconds.", utils.timer () - start))
477
514
478
515
end -- if
0 commit comments