From efd03cccb309cef3b90886474e06c6fe9ef96f5d Mon Sep 17 00:00:00 2001 From: steve donovan Date: Wed, 6 Jul 2011 11:49:24 +0200 Subject: [PATCH] Markdown preprocess: consistently indented blocks are given paragraph break lines around them. Use ldoc.classic_markdown to switch off --- ldoc.lua | 4 ++-- ldoc/markup.lua | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ldoc.lua b/ldoc.lua index d3bb271..c57d951 100644 --- a/ldoc.lua +++ b/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) diff --git a/ldoc/markup.lua b/ldoc/markup.lua index 112f2af..5e28d2e 100644 --- a/ldoc/markup.lua +++ b/ldoc/markup.lua @@ -13,25 +13,42 @@ 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 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 - 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 not line:match '^%s*$' then --ignore blank lines + local indent = #line:match '^%s*' + 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') + txt = table.concat(res,'\n') end txt = markup(txt) -- We will add our own paragraph tags, if needed.