diff --git a/ldoc.lua b/ldoc.lua index d1dd3cd..d2f184d 100644 --- a/ldoc.lua +++ b/ldoc.lua @@ -39,6 +39,7 @@ local lang = require 'ldoc.lang' local Item,File,Module = doc.Item,doc.File,doc.Module local tools = require 'ldoc.tools' local global = require 'builtin.globals' +local markup = require 'ldoc.markup' local KindMap = tools.KindMap class.ModuleMap(KindMap) @@ -612,15 +613,9 @@ if not module_template then end if args.format ~= 'plain' then - local ok,markup = pcall(require,args.format) - if not ok then quit("cannot load formatter: "..args.format) end - function ldoc.markup(txt) - if txt == nil then return '' end - txt = markup(txt) - return (txt:gsub('^%s*

(.+)

%s*$','%1')) - end + ldoc.markup = markup.create(args.format) else - function ldoc.markup(txt) + ldoc.markup = function (txt) return txt end end diff --git a/ldoc/markup.lua b/ldoc/markup.lua new file mode 100644 index 0000000..9604c03 --- /dev/null +++ b/ldoc/markup.lua @@ -0,0 +1,21 @@ +-------------- +-- Handling markup transformation. +-- Currently just does Markdown, but this is intended to +-- be the general module for managing other formats as well. + +local utils = require 'pl.utils' +local quit = utils.quit +local markup = {} + +function markup.create (format) + local ok,markup = pcall(require,format) + if not ok then quit("cannot load formatter: "..format) end + return function (txt) + if txt == nil then return '' end + txt = markup(txt) + return (txt:gsub('^%s*

(.+)

%s*$','%1')) + end +end + + +return markup