Markdown preprocess: consistently indented blocks are given paragraph break lines around them. Use ldoc.classic_markdown to switch off
This commit is contained in:
parent
67c4a795af
commit
efd03cccb3
4
ldoc.lua
4
ldoc.lua
|
@ -157,8 +157,8 @@ local function extract_tags (s)
|
|||
local preamble,tag_items = parse_tags(s)
|
||||
local strip = tools.strip
|
||||
local summary,description = preamble:match('^(.-[%.?])%s(.+)')
|
||||
if not summary then summary = preamble end
|
||||
local tags = {summary=summary and strip(summary),description=description and strip(description)}
|
||||
if not summary then summary = preamble end -- and strip(description) ?
|
||||
local tags = {summary=summary and strip(summary),description=description}
|
||||
for _,item in ipairs(tag_items) do
|
||||
local tag,value = item[1],item[2]
|
||||
tag = Item.check_tag(tags,tag)
|
||||
|
|
|
@ -13,23 +13,40 @@ function markup.create (ldoc, format)
|
|||
if not ok then quit("cannot load formatter: "..format) end
|
||||
return function (txt)
|
||||
if txt == nil then return '' end
|
||||
txt = txt:gsub('<<([%w_%.]-)>>',function(ref)
|
||||
local ref = ldoc.module:process_see_reference(ref,ldoc.modules)
|
||||
-- inline <references> use same lookup as @see
|
||||
txt = txt:gsub('<([%w_%.]-)>',function(name)
|
||||
local ref = ldoc.module:process_see_reference(name,ldoc.modules)
|
||||
if not ref then print("could not find '"..name.."'"); return '' end
|
||||
local label = ref.label:gsub('_','\\_')
|
||||
local res = ('[%s](%s)'):format(label,ldoc.href(ref))
|
||||
return res
|
||||
end)
|
||||
if txt:find '\n' then -- multiline text
|
||||
local res = {}
|
||||
local last_line, last_indent = '', 0
|
||||
-- workaround Markdown's need for blank lines around indented blocks
|
||||
-- (does mean you have to keep indentation discipline!)
|
||||
if txt:find '\n' and not ldoc.classic_markdown then -- multiline text
|
||||
local res, append = {}, table.insert
|
||||
local last_indent, start_indent, skip = -1, -1, false
|
||||
for line in stringx.lines(txt) do
|
||||
if not line:match '^%s*$' then --ignore blank lines
|
||||
local indent = #line:match '^%s*'
|
||||
local litem = line:match '^%s%s*[%-%*]'
|
||||
if (litem and indent > last_indent) or (not litem and indent < last_indent) then
|
||||
table.insert(res,'')
|
||||
if start_indent < 0 then -- initialize indents at start
|
||||
start_indent = indent
|
||||
last_indent = indent
|
||||
end
|
||||
if indent < start_indent then -- end of indented block
|
||||
append(res,'')
|
||||
skip = false
|
||||
end
|
||||
if not skip and indent > last_indent then -- start of indent
|
||||
append(res,'')
|
||||
skip = true
|
||||
start_indent = indent
|
||||
end
|
||||
append(res,line)
|
||||
last_indent = indent
|
||||
else
|
||||
append(res,'')
|
||||
end
|
||||
table.insert(res,line)
|
||||
last_line, last_indent = line, indent
|
||||
end
|
||||
txt = table.concat(res,'\n')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue