mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 08:25:32 +00:00
38 lines
1.1 KiB
Lua
38 lines
1.1 KiB
Lua
local redirect
|
|
|
|
function Link(elem)
|
|
if isLocalLink(elem) then
|
|
if isFolderLink(elem) then
|
|
return pandoc.Link(elem.content, elem.target .. 'index.htm', elem.title, elem.attr)
|
|
else
|
|
return pandoc.Link(elem.content, elem.target .. '.htm', elem.title, elem.attr)
|
|
end
|
|
end
|
|
return elem
|
|
end
|
|
|
|
function isLocalLink(elem)
|
|
return string.match(elem.target, "://") == nil
|
|
end
|
|
|
|
function isFolderLink(elem)
|
|
return not ( string.match(elem.target, "/$") == nil )
|
|
end
|
|
|
|
-- Support for redirect meta key, adds a meta refresh to the resulting document
|
|
function Meta(meta)
|
|
if meta.redirect then
|
|
redirect = pandoc.utils.stringify(meta.redirect)
|
|
end
|
|
return meta
|
|
end
|
|
|
|
function Pandoc(doc)
|
|
if redirect then
|
|
local metaRefresh = pandoc.RawBlock('html', "<meta http-equiv='refresh' content='0;url=" .. redirect .. ".htm'>")
|
|
local redirectText = pandoc.Para({pandoc.Str("This content can be found "), pandoc.Link("here", redirect .. ".htm"), pandoc.Str(".")})
|
|
table.insert(doc.blocks, metaRefresh)
|
|
table.insert(doc.blocks, redirectText)
|
|
end
|
|
return pandoc.Pandoc(doc.blocks, doc.meta)
|
|
end
|