prettify code blocks in module docstring. Two new ldoc flags: dont_escape_underscore (when not using markdown.lua) and global_lookup (when specifically wanting global lookup for single symbols

This commit is contained in:
Steve Donovan 2014-06-20 15:11:40 +02:00
parent a0c780f093
commit acc6ed2ad3
3 changed files with 29 additions and 10 deletions

View File

@ -1142,6 +1142,13 @@ function Module:process_see_reference (s,modules,istype)
end end
end end
else -- plain jane name; module in this package, function in this module else -- plain jane name; module in this package, function in this module
if ldoc.global_lookup then
for m in modules:iter() do
fun_ref = m:get_fun_ref(s)
if fun_ref then return reference(s,m,fun_ref) end
end
return nil,"function: "..s.." not found globally"
end
mod_ref = modules.by_name[self.package..'.'..s] mod_ref = modules.by_name[self.package..'.'..s]
if ismod(mod_ref) then return reference(s, mod_ref,nil) end if ismod(mod_ref) then return reference(s, mod_ref,nil) end
fun_ref = self:get_fun_ref(s) fun_ref = self:get_fun_ref(s)

View File

@ -42,7 +42,8 @@ local function resolve_inline_references (ldoc, txt, item, plain)
if not label then if not label then
label = ref.label label = ref.label
end end
if not plain and label then -- a nastiness with markdown.lua and underscores local do_escape = not plain and not ldoc.dont_escape_underscore
if label and do_escape then -- a nastiness with markdown.lua and underscores
label = label:gsub('_','\\_') label = label:gsub('_','\\_')
end end
local html = ldoc.href(ref) or '#' local html = ldoc.href(ref) or '#'
@ -54,7 +55,7 @@ local function resolve_inline_references (ldoc, txt, item, plain)
res = res:gsub('`([^`]+)`',function(name) res = res:gsub('`([^`]+)`',function(name)
local ref,err = markup.process_reference(name) local ref,err = markup.process_reference(name)
if ref then if ref then
if not plain and name then if name and do_escape then
name = name:gsub('_', '\\_') name = name:gsub('_', '\\_')
end end
return ('<a href="%s">%s</a> '):format(ldoc.href(ref),name) return ('<a href="%s">%s</a> '):format(ldoc.href(ref),name)
@ -115,9 +116,8 @@ local global_context, local_context
-- - insert any section ids which were generated by add_sections above -- - insert any section ids which were generated by add_sections above
-- - prettify any code blocks -- - prettify any code blocks
local function process_multiline_markdown(ldoc, txt, F) local function process_multiline_markdown(ldoc, txt, F, filename, deflang)
local res, L, append = {}, 0, table.insert local res, L, append = {}, 0, table.insert
local filename = F.filename
local err_item = { local err_item = {
warning = function (self,msg) warning = function (self,msg)
io.stderr:write(filename..':'..L..': '..msg,'\n') io.stderr:write(filename..':'..L..': '..msg,'\n')
@ -135,6 +135,7 @@ local function process_multiline_markdown(ldoc, txt, F)
-- If we omit the following '\n', a '--' (or '//') comment on the -- If we omit the following '\n', a '--' (or '//') comment on the
-- last line won't be recognized. -- last line won't be recognized.
code, err = prettify.code(lang,filename,code..'\n',L,false) code, err = prettify.code(lang,filename,code..'\n',L,false)
code = resolve_inline_references(ldoc, code, err_item)
append(res,'<pre>') append(res,'<pre>')
append(res, code) append(res, code)
append(res,'</pre>') append(res,'</pre>')
@ -192,9 +193,9 @@ local function process_multiline_markdown(ldoc, txt, F)
while #code > 1 and blank(code[#code]) do -- trim blank lines. while #code > 1 and blank(code[#code]) do -- trim blank lines.
table.remove(code) table.remove(code)
end end
pretty_code (code,'lua') pretty_code (code,deflang)
else else
local section = F.sections[L] local section = F and F.sections[L]
if section then if section then
append(res,('<a name="%s"></a>'):format(section)) append(res,('<a name="%s"></a>'):format(section))
end end
@ -274,8 +275,18 @@ local function markdown_processor(ldoc, formatter)
end end
return plain_processor(txt,item) return plain_processor(txt,item)
end end
if utils.is_type(item,doc.File) then local is_file = utils.is_type(item,doc.File)
txt = process_multiline_markdown(ldoc, txt, item) local is_module = not file and item and doc.project_level(item.type)
if is_file or is_module then
local deflang = 'lua'
if ldoc.parse_extra and ldoc.parse_extra.C then
deflang = 'c'
end
if is_module then
txt = process_multiline_markdown(ldoc, txt, nil, item.file.filename, deflang)
else
txt = process_multiline_markdown(ldoc, txt, item, item.filename, deflang)
end
else else
txt = resolve_inline_references(ldoc, txt, item) txt = resolve_inline_references(ldoc, txt, item)
end end

View File

@ -109,6 +109,7 @@ function KindMap:add (item,items,description)
local group = item[self.fieldname] -- which wd be item's type or section local group = item[self.fieldname] -- which wd be item's type or section
local kname = self.klass.types_by_tag[group] -- the kind name local kname = self.klass.types_by_tag[group] -- the kind name
if not self[kname] then if not self[kname] then
-- print(kname,group,self.fieldname)
self[kname] = M.type_iterator (items,self.fieldname,group) self[kname] = M.type_iterator (items,self.fieldname,group)
self.klass.descriptions[kname] = description self.klass.descriptions[kname] = description
end end