From 7ceb7cc00ba361e311afe071431cf14ad3c49da1 Mon Sep 17 00:00:00 2001 From: steve donovan Date: Tue, 5 Mar 2013 16:21:54 +0200 Subject: [PATCH] @usage code blocks are prettified --- ldoc/html.lua | 5 +++++ ldoc/html/ldoc_ltp.lua | 2 +- ldoc/prettify.lua | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ldoc/html.lua b/ldoc/html.lua index 89f0401..5c16366 100644 --- a/ldoc/html.lua +++ b/ldoc/html.lua @@ -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 diff --git a/ldoc/html/ldoc_ltp.lua b/ldoc/html/ldoc_ltp.lua index 81ffe86..d048d03 100644 --- a/ldoc/html/ldoc_ltp.lua +++ b/ldoc/html/ldoc_ltp.lua @@ -195,7 +195,7 @@ return [==[

Usage:

# end -- if usage diff --git a/ldoc/prettify.lua b/ldoc/prettify.lua index e275c75..51f4827 100644 --- a/ldoc/prettify.lua +++ b/ldoc/prettify.lua @@ -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 '
\n'
+   if not no_pre then
+      res:append '
\n'
+   end
    initial_lineno = initial_lineno or 0
 
    local tok = lexer.lua(code,{},{})