Skip to content

Commit a387512

Browse files
committed
Improved snippet displays by removing tags from the lookup tables
1 parent 727cdeb commit a387512

File tree

1 file changed

+90
-53
lines changed

1 file changed

+90
-53
lines changed

plugins/MUSHclient_Help.xml

Lines changed: 90 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ end -- text_output
180180
local P, R, S, C, Cc, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Ct
181181
local TAG = (P"<" * P"/"^-1 * R("AZ", "az")^1 * P"/"^-1 * P">")/tag_output
182182
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
184184
185185
-- show a help item with a coloured heading, and coloured text
186186
@@ -211,7 +211,6 @@ end -- show_item
211211
212212
-- normal functions
213213
local function show_functions_help (row)
214-
215214
NoteHr ()
216215
show_item (HEADINGCOLOUR, "Function", NAMECOLOUR, row.name)
217216
show_item (HEADINGCOLOUR, "Summary", SUMMARYCOLOUR, row.summary)
@@ -220,27 +219,22 @@ local function show_functions_help (row)
220219
show_item (HEADINGCOLOUR, "Return Value", RETURNVALUE, row.return_value)
221220
show_item (HEADINGCOLOUR, "Lua Example", CODECOLOUR, row.lua_example)
222221
show_item (HEADINGCOLOUR, "Lua Notes", NOTESCOLOUR, row.lua_notes)
223-
224222
end -- show_functions_help
225223
226224
-- general help (major topics)
227225
local function show_general_help (row)
228-
229226
NoteHr ()
230227
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
233229
end -- show_general_help
234230
235231
-- lua functions
236232
local function show_lua_functions_help (row)
237-
238233
NoteHr ()
239234
show_item (HEADINGCOLOUR, "Lua", NAMECOLOUR, row.name)
240235
show_item (HEADINGCOLOUR, "Summary", SUMMARYCOLOUR, row.summary)
241236
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
244238
end -- show_lua_functions_help
245239
246240
@@ -306,20 +300,8 @@ function general_help (search_string, want_snippet)
306300
-- show snippet
307301
308302
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+", " "))
323305
print ""
324306
end -- if snippet wanted
325307
@@ -406,6 +388,20 @@ function help_find_snippet (name, line, wildcards)
406388
general_help (wildcards [1], true)
407389
end -- help_find_snippet
408390
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+
409405
function OnPluginInstall ()
410406
-- open database on disk
411407
@@ -438,41 +434,82 @@ function OnPluginInstall ()
438434
if not fts4 then
439435
local start = utils.timer ()
440436
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
453461
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
458474
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]])
463479
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
468492
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 ]])
473497
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;")
476513
ColourNote ("cyan", "", string.format ("Done. Took %0.3f seconds.", utils.timer () - start))
477514
478515
end -- if

0 commit comments

Comments
 (0)