factoring out custom markup processing

This commit is contained in:
steve donovan 2011-07-05 16:30:49 +02:00
parent 2810c4804a
commit e21db67984
2 changed files with 24 additions and 8 deletions

View File

@ -39,6 +39,7 @@ local lang = require 'ldoc.lang'
local Item,File,Module = doc.Item,doc.File,doc.Module local Item,File,Module = doc.Item,doc.File,doc.Module
local tools = require 'ldoc.tools' local tools = require 'ldoc.tools'
local global = require 'builtin.globals' local global = require 'builtin.globals'
local markup = require 'ldoc.markup'
local KindMap = tools.KindMap local KindMap = tools.KindMap
class.ModuleMap(KindMap) class.ModuleMap(KindMap)
@ -612,15 +613,9 @@ if not module_template then
end end
if args.format ~= 'plain' then if args.format ~= 'plain' then
local ok,markup = pcall(require,args.format) ldoc.markup = markup.create(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*<p>(.+)</p>%s*$','%1'))
end
else else
function ldoc.markup(txt) ldoc.markup = function (txt)
return txt return txt
end end
end end

21
ldoc/markup.lua Normal file
View File

@ -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*<p>(.+)</p>%s*$','%1'))
end
end
return markup