Markdown preprocess: consistently indented blocks are given paragraph break lines around them. Use ldoc.classic_markdown to switch off

This commit is contained in:
steve donovan 2011-07-06 11:49:24 +02:00
parent 67c4a795af
commit efd03cccb3
2 changed files with 31 additions and 14 deletions

View File

@ -157,8 +157,8 @@ local function extract_tags (s)
local preamble,tag_items = parse_tags(s) local preamble,tag_items = parse_tags(s)
local strip = tools.strip local strip = tools.strip
local summary,description = preamble:match('^(.-[%.?])%s(.+)') local summary,description = preamble:match('^(.-[%.?])%s(.+)')
if not summary then summary = preamble end if not summary then summary = preamble end -- and strip(description) ?
local tags = {summary=summary and strip(summary),description=description and strip(description)} local tags = {summary=summary and strip(summary),description=description}
for _,item in ipairs(tag_items) do for _,item in ipairs(tag_items) do
local tag,value = item[1],item[2] local tag,value = item[1],item[2]
tag = Item.check_tag(tags,tag) tag = Item.check_tag(tags,tag)

View File

@ -13,25 +13,42 @@ function markup.create (ldoc, format)
if not ok then quit("cannot load formatter: "..format) end if not ok then quit("cannot load formatter: "..format) end
return function (txt) return function (txt)
if txt == nil then return '' end if txt == nil then return '' end
txt = txt:gsub('<<([%w_%.]-)>>',function(ref) -- inline <references> use same lookup as @see
local ref = ldoc.module:process_see_reference(ref,ldoc.modules) 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 label = ref.label:gsub('_','\\_')
local res = ('[%s](%s)'):format(label,ldoc.href(ref)) local res = ('[%s](%s)'):format(label,ldoc.href(ref))
return res return res
end) end)
if txt:find '\n' then -- multiline text -- workaround Markdown's need for blank lines around indented blocks
local res = {} -- (does mean you have to keep indentation discipline!)
local last_line, last_indent = '', 0 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 for line in stringx.lines(txt) do
local indent = #line:match '^%s*' if not line:match '^%s*$' then --ignore blank lines
local litem = line:match '^%s%s*[%-%*]' local indent = #line:match '^%s*'
if (litem and indent > last_indent) or (not litem and indent < last_indent) then if start_indent < 0 then -- initialize indents at start
table.insert(res,'') 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 end
table.insert(res,line)
last_line, last_indent = line, indent
end end
txt = table.concat(res,'\n') txt = table.concat(res,'\n')
end end
txt = markup(txt) txt = markup(txt)
-- We will add our own paragraph tags, if needed. -- We will add our own paragraph tags, if needed.