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:
parent
a0c780f093
commit
acc6ed2ad3
|
@ -1142,6 +1142,13 @@ function Module:process_see_reference (s,modules,istype)
|
|||
end
|
||||
end
|
||||
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]
|
||||
if ismod(mod_ref) then return reference(s, mod_ref,nil) end
|
||||
fun_ref = self:get_fun_ref(s)
|
||||
|
|
|
@ -42,7 +42,8 @@ local function resolve_inline_references (ldoc, txt, item, plain)
|
|||
if not label then
|
||||
label = ref.label
|
||||
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('_','\\_')
|
||||
end
|
||||
local html = ldoc.href(ref) or '#'
|
||||
|
@ -54,7 +55,7 @@ local function resolve_inline_references (ldoc, txt, item, plain)
|
|||
res = res:gsub('`([^`]+)`',function(name)
|
||||
local ref,err = markup.process_reference(name)
|
||||
if ref then
|
||||
if not plain and name then
|
||||
if name and do_escape then
|
||||
name = name:gsub('_', '\\_')
|
||||
end
|
||||
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
|
||||
-- - 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 filename = F.filename
|
||||
local err_item = {
|
||||
warning = function (self,msg)
|
||||
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
|
||||
-- last line won't be recognized.
|
||||
code, err = prettify.code(lang,filename,code..'\n',L,false)
|
||||
code = resolve_inline_references(ldoc, code, err_item)
|
||||
append(res,'<pre>')
|
||||
append(res, code)
|
||||
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.
|
||||
table.remove(code)
|
||||
end
|
||||
pretty_code (code,'lua')
|
||||
pretty_code (code,deflang)
|
||||
else
|
||||
local section = F.sections[L]
|
||||
local section = F and F.sections[L]
|
||||
if section then
|
||||
append(res,('<a name="%s"></a>'):format(section))
|
||||
end
|
||||
|
@ -274,8 +275,18 @@ local function markdown_processor(ldoc, formatter)
|
|||
end
|
||||
return plain_processor(txt,item)
|
||||
end
|
||||
if utils.is_type(item,doc.File) then
|
||||
txt = process_multiline_markdown(ldoc, txt, item)
|
||||
local is_file = utils.is_type(item,doc.File)
|
||||
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
|
||||
txt = resolve_inline_references(ldoc, txt, item)
|
||||
end
|
||||
|
|
|
@ -109,6 +109,7 @@ function KindMap:add (item,items,description)
|
|||
local group = item[self.fieldname] -- which wd be item's type or section
|
||||
local kname = self.klass.types_by_tag[group] -- the kind name
|
||||
if not self[kname] then
|
||||
-- print(kname,group,self.fieldname)
|
||||
self[kname] = M.type_iterator (items,self.fieldname,group)
|
||||
self.klass.descriptions[kname] = description
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue