Merge pull request #130 from mooffie/fix_prettifier_last_lines
Fix minor issues with the "prettify" facility.
This commit is contained in:
commit
c93c14709f
|
@ -90,8 +90,8 @@ local function indent_line (line)
|
||||||
return indent,line
|
return indent,line
|
||||||
end
|
end
|
||||||
|
|
||||||
local function non_blank (line)
|
local function blank (line)
|
||||||
return line:find '%S'
|
return not line:find '%S'
|
||||||
end
|
end
|
||||||
|
|
||||||
local global_context, local_context
|
local global_context, local_context
|
||||||
|
@ -119,6 +119,8 @@ local function process_multiline_markdown(ldoc, txt, F)
|
||||||
code = concat(code,'\n')
|
code = concat(code,'\n')
|
||||||
if code ~= '' then
|
if code ~= '' then
|
||||||
local err
|
local err
|
||||||
|
-- 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, err = prettify.code(lang,filename,code..'\n',L,false)
|
||||||
append(res,'<pre>')
|
append(res,'<pre>')
|
||||||
append(res, code)
|
append(res, code)
|
||||||
|
@ -156,7 +158,7 @@ local function process_multiline_markdown(ldoc, txt, F)
|
||||||
if indent >= 4 then -- indented code block
|
if indent >= 4 then -- indented code block
|
||||||
local code = {}
|
local code = {}
|
||||||
local plain
|
local plain
|
||||||
while indent >= 4 or not non_blank(line) do
|
while indent >= 4 or blank(line) do
|
||||||
if not start_indent then
|
if not start_indent then
|
||||||
start_indent = indent
|
start_indent = indent
|
||||||
if line:match '^%s*@plain%s*$' then
|
if line:match '^%s*@plain%s*$' then
|
||||||
|
@ -165,7 +167,7 @@ local function process_multiline_markdown(ldoc, txt, F)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not plain then
|
if not plain then
|
||||||
append(code,line:sub(start_indent))
|
append(code,line:sub(start_indent + 1))
|
||||||
else
|
else
|
||||||
append(res,line)
|
append(res,line)
|
||||||
end
|
end
|
||||||
|
@ -174,7 +176,9 @@ local function process_multiline_markdown(ldoc, txt, F)
|
||||||
indent, line = indent_line(line)
|
indent, line = indent_line(line)
|
||||||
end
|
end
|
||||||
start_indent = nil
|
start_indent = nil
|
||||||
if #code > 1 then table.remove(code) end
|
while #code > 1 and blank(code[#code]) do -- trim blank lines.
|
||||||
|
table.remove(code)
|
||||||
|
end
|
||||||
pretty_code (code,'lua')
|
pretty_code (code,'lua')
|
||||||
else
|
else
|
||||||
local section = F.sections[L]
|
local section = F.sections[L]
|
||||||
|
|
|
@ -89,7 +89,7 @@ function prettify.code (lang,fname,code,initial_lineno,pre)
|
||||||
external = true
|
external = true
|
||||||
})
|
})
|
||||||
if not pre then
|
if not pre then
|
||||||
code = code:gsub("^<pre*.->(.*)</pre>$", '%1')
|
code = code:gsub("^<pre.->(.-)%s*</pre>$", '%1')
|
||||||
end
|
end
|
||||||
return code
|
return code
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue