local nb = {
dev = 1,
}
-local discount = nil
+local md2html_discount = nil
if ngx and ngx.var.PRODUCTION == 'yes' then nb.dev = 0 end
self:ngx_location_tmpl(fheader,ffooter)
end
-function nb:ngx_tmpl(content,fheader,ffooter)
+function nb:ngx_tmpl_content(content,fheader,ffooter)
ngx.ctx.tmpl_content = content
self:ngx_location_tmpl(fheader,ffooter)
end
-- content_by_lua_block { package.path = ngx.var.NB_ROOT .. "/lib/lua/?.lua;" .. package.path local nb = require("nb") nb:ngx_location_tmpl() }
-- }
local root = ngx.var.document_root
- local file = root .. ngx.var.uri;
+-- NB 02.06.18 local file = root .. ngx.var.uri;
+ local file = ngx.var.request_filename;
local path = file:gsub('/[^/]+$','')
- local vars = {}
+ local vars = {
+ }
if not fheader then fheader = root .. "/header.tmpl.html" end
if not ffooter then ffooter = root .. "/footer.tmpl.html" end
elseif not ngx.ctx.tmpl_content then
ishtml = false
+ if not vars.title then vars.title = string.match(content,'<title[^>]*>(.*)</title>',1) end
end
-- Header and footer
return str:match("(.*)/")
end
-function nb:filepath2name(inc)
- local name = inc
+-- function nb.filepath2name(filepath) return nb:gsub(filepath) end
+function nb:filepath2name(filepath)
+ local name = filepath
name = name:gsub('%.[^/]+$','')
name = name:gsub('/index$','')
+ name = name:gsub('^[^%w]+',''):gsub('[^%w]+$','')
name = name:gsub('[^%w]+','-')
return name
end
content = content:gsub('<p><div','<div')
content = content:gsub('div></p>','div>')
content = content:gsub('[%s]*<tr>[%s]*<th>[%s]*</th>[%s]*<th>[%s]*</th>[%s]*</tr>[%s]*','')
+
+ -- xHtml
+ content = content:gsub('<(hr)>','<%1/>')
+
return content
end
function nb:md2html(content)
- if self.discount == nil then self.discount = require("discount") end
- content = self.discount(content)
+ if self.md2html_discount == nil then self.md2html_discount = require("discount") end
+ content = self.md2html_discount(content)
if content then
content = '<div class="md">' .. content .. '</div>'
end