2 files changed, 20 insertions(+), 5 deletions(-)
M Makefile
R promote-h1-to-title.lua => markdown-to-website.lua
M Makefile => Makefile +1 -1
@@ 15,7 15,7 @@ LUA := fennelview.lua
# This requires pandoc 2.0+
PANDOC ?= pandoc --syntax-definition fennel-syntax.xml \
-H head.html -A foot.html -T "Fennel" \
- --lua-filter=promote-h1-to-title.lua
+ --lua-filter=markdown-to-website.lua
fennel/fennel: ; make -C fennel fennel
fennel/fennel.lua: ; make -C fennel fennel.lua
R promote-h1-to-title.lua => markdown-to-website.lua +19 -4
@@ 1,7 1,11 @@
local title
+local function warn(msg)
+ io.stderr:write(("%s\n"):format(msg))
+end
+
-- Set title from level 1 headers, unless it has been set before.
-function promote_header (header)
+local function promote_header (header)
if header.level >= 2 then
return header
end
@@ 11,14 15,25 @@ function promote_header (header)
return {}
end
- local msg = '[WARNING] title already set; demoting header "%s"\n'
- io.stderr:write(msg:format(pandoc.utils.stringify(header)))
+ local msg = '[WARNING] title already set; demoting header "%s"'
+ warn(msg:format(pandoc.utils.stringify(header)))
header.level = header.level + 1
return header
end
+local function link_strip_md_ext_from_link_tgt(link)
+ if not link.target:match("^https?") then
+ local old_target = link.target
+ link.target = link.target:gsub("%.md$", "")
+ if os.getenv('PANDOC_FILTER_VERBOSE') and old_target ~= link.target then
+ warn(('[DEBUG] %s -> %s'):format(old_target, link.target))
+ end
+ end
+ return link
+end
+
return {
{Meta = function (meta) title = meta.title end}, -- init title
- {Header = promote_header},
+ {Header = promote_header, Link = link_strip_md_ext_from_link_tgt},
{Meta = function (meta) meta.title = title; return meta end}, -- set title
}