Codebase list lua-ldoc / 22e7055
Have postprocess_html Mooffie 9 years ago
3 changed file(s) with 25 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
12771277 - `user_keywords` A list of keywords that will be marked in "prettified" code. Useful if
12781278 you want to display your own functions in a special way. Each keyword may be styled differently
12791279 (using CSS). Only works when `pretty` is set to 'lua' (the default).
1280 - `postprocess_html` function that allows a last-minute modification to the produced HTML page.
1281 The arguments are the raw HTML that's intended to be written out (a string), and the module object.
1282 The string this function returns will be what's actually gets written out.
12801283
12811284 _Available functions are:_
12821285
277277 quit("template not found at '"..args.template.."' Use -l to specify directory containing ldoc.ltp")
278278 end
279279
280 -- Runs a template on a module to generate HTML page.
281 local function templatize(template_str, ldoc, module)
282 local out, err = template.substitute(template_str, {
283 ldoc = ldoc,
284 module = module,
285 _escape = ldoc.template_escape
286 })
287 if not out then
288 quit(("template failed for %s: %s"):format(
289 module and module.name or ldoc.output or "index",
290 err))
291 end
292 if ldoc.postprocess_html then
293 out = ldoc.postprocess_html(out, module)
294 end
295 return cleanup_whitespaces(out)
296 end
297
280298 local css = ldoc.css
281299 ldoc.output = args.output
282300 ldoc.ipairs = ipairs
298316 save_and_set_ldoc(ldoc.module.tags.set)
299317 end
300318 set_charset(ldoc)
301 local out,err = template.substitute(module_template,{
302 ldoc = ldoc,
303 module = ldoc.module,
304 _escape = ldoc.template_escape
305 })
319 local out = templatize(module_template, ldoc, ldoc.module)
306320 ldoc.root = false
307 if not out then quit("template failed: "..err) end
308321 restore_ldoc()
309322
310323 check_directory(args.dir) -- make sure output directory is ok
351364 if ldoc.body and m.postprocess then
352365 ldoc.body = m.postprocess(ldoc.body)
353366 end
354 out,err = template.substitute(module_template,{
355 module=m,
356 ldoc = ldoc,
357 _escape = ldoc.template_escape
358 })
359 if not out then
360 quit('template failed for '..m.name..': '..err)
361 else
362 out = cleanup_whitespaces(out)
363 writefile(args.dir..lkind..'/'..m.name..args.ext,out)
364 end
367 local out = templatize(module_template, ldoc, m)
368 writefile(args.dir..lkind..'/'..m.name..args.ext,out)
365369 restore_ldoc()
366370 end
367371 end
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',
235235 'dont_escape_underscore','global_lookup','prettify_files','convert_opt', 'user_keywords',
236 'postprocess_html',
236237 }
237238 ldoc_contents = tablex.makeset(ldoc_contents)
238239