@usage code blocks are prettified

This commit is contained in:
steve donovan 2013-03-05 16:21:54 +02:00
parent 9f52eacb05
commit 7ceb7cc00b
3 changed files with 10 additions and 3 deletions

View File

@ -20,6 +20,7 @@ local stringx = require 'pl.stringx'
local template = require 'pl.template'
local tools = require 'ldoc.tools'
local markup = require 'ldoc.markup'
local prettify = require 'ldoc.prettify'
local doc = require 'ldoc.doc'
local html = {}
@ -59,6 +60,10 @@ function html.generate_output(ldoc, args, project)
return (str:gsub("['&<>\"]", escape_table))
end
function ldoc.prettify(str)
return prettify.lua('tmp',str,0,true)
end
-- this generates the internal module/function references
function ldoc.href(see)
if see.href then -- explict reference, e.g. to Lua manual

View File

@ -195,7 +195,7 @@ return [==[
<h3>Usage:</h3>
<ul>
# for usage in iter(item.usage) do
$(li)<pre class="example">$(ldoc.escape(usage))</pre>$(il)
$(li)<pre class="example">$(ldoc.prettify(usage))</pre>$(il)
# end -- for
</ul>
# end -- if usage

View File

@ -26,9 +26,11 @@ end
local spans = {keyword=true,number=true,string=true,comment=true,global=true}
function prettify.lua (fname, code, initial_lineno)
function prettify.lua (fname, code, initial_lineno, no_pre)
local res = List()
res:append '<pre>\n'
if not no_pre then
res:append '<pre>\n'
end
initial_lineno = initial_lineno or 0
local tok = lexer.lua(code,{},{})