Codebase list lua-ldoc / 3313e78
Support used-defined keywords (in prettified code). Mooffie 9 years ago
8 changed file(s) with 23 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
12741274 - `no_space_before_args` set to `true` if you do not want a space between a function's name and its arguments.
12751275 - `template_escape` overrides the usual '#' used for Lua code in templates.
12761276 This needs to be changed if the output format is Markdown, for instance.
1277 - `user_keywords` A list of keywords that will be marked in "prettified" code. Useful if
1278 you want to display your own functions in a special way. Each keyword may be styled differently
1279 (using CSS). Only works when `pretty` is set to 'lua' (the default).
12771280
12781281 _Available functions are:_
12791282
303303 pre .operator { color: #2239a8; font-weight: bold; }
304304 pre .preprocessor, pre .prepro { color: #a33243; }
305305 pre .global { color: #800080; }
306 pre .user-keyword { color: #800080; }
306307 pre .prompt { color: #558817; }
307308 pre .url { color: #272fc2; text-decoration: underline; }
308309 ]==]
311311 pre .operator { color: #2239a8; font-weight: bold; }
312312 pre .preprocessor, pre .prepro { color: #a33243; }
313313 pre .global { color: #800080; }
314 pre .user-keyword { color: #800080; }
314315 pre .prompt { color: #558817; }
315316 pre .url { color: #272fc2; text-decoration: underline; }
316317 ]]
279279 pre .operator { color: #2239a8; font-weight: bold; }
280280 pre .preprocessor, pre .prepro { color: #a33243; }
281281 pre .global { color: #800080; }
282 pre .user-keyword { color: #800080; }
282283 pre .prompt { color: #558817; }
283284 pre .url { color: #272fc2; text-decoration: underline; }
284285 ]==]
302302 pre .operator { color: #2239a8; font-weight: bold; }
303303 pre .preprocessor, pre .prepro { color: #a33243; }
304304 pre .global { color: #800080; }
305 pre .user-keyword { color: #800080; }
305306 pre .prompt { color: #558817; }
306307 pre .url { color: #272fc2; text-decoration: underline; }
307308 ]]
318318 end
319319
320320
321 function markup.create (ldoc, format, pretty)
321 function markup.create (ldoc, format, pretty, user_keywords)
322322 local processor
323323 markup.plain = true
324324 if format == 'backtick' then
328328 backtick_references = ldoc.backtick_references
329329 global_context = ldoc.package and ldoc.package .. '.'
330330 prettify.set_prettifier(pretty)
331 prettify.set_user_keywords(user_keywords)
331332
332333 markup.process_reference = function(name,istype)
333334 if local_context == 'none.' and not name:match '%.' then
33 -- A module reference to an example `test-fun.lua` would look like
44 -- `@{example:test-fun}`.
55 local List = require 'pl.List'
6 local tablex = require 'pl.tablex'
67 local globals = require 'ldoc.builtin.globals'
78 local prettify = {}
9
10 local user_keywords = {}
811
912 local escaped_chars = {
1013 ['&'] = '&',
5760 if globals.functions[val] or globals.tables[val] then
5861 t = 'global'
5962 end
60 if spans[t] then
63 if user_keywords[val] then
64 res:append(span('user-keyword keyword-' .. val,val))
65 elseif spans[t] then
6166 if t == 'comment' or t == 'backtick' then -- may contain @{ref} or `..`
6267 val = prettify.resolve_inline_references(val,error_reporter)
6368 end
110115 end
111116 end
112117
118 function prettify.set_user_keywords(keywords)
119 if keywords then
120 user_keywords = tablex.makeset(keywords)
121 end
122 end
123
113124 return prettify
114125
232232 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler',
233233 'no_space_before_args','parse_extra','no_lua_ref','sort_modules','use_markdown_titles',
234234 'unqualified', 'custom_display_name_handler', 'kind_names', 'custom_references',
235 'dont_escape_underscore','global_lookup','prettify_files','convert_opt'
235 'dont_escape_underscore','global_lookup','prettify_files','convert_opt', 'user_keywords',
236236 }
237237 ldoc_contents = tablex.makeset(ldoc_contents)
238238
503503 -- (this also will initialize the code prettifier used)
504504 override ('format','plain')
505505 override 'pretty'
506 ldoc.markup = markup.create(ldoc, args.format,args.pretty)
506 ldoc.markup = markup.create(ldoc, args.format, args.pretty, ldoc.user_keywords)
507507
508508 ------ 'Special' Project-level entities ---------------------------------------
509509 -- Examples and Topics do not contain code to be processed for doc comments.