~technomancy/fennel-lang.org

ref: c9a7db72fe3fd06b5eec936984713f034acd9511 fennel-lang.org/promote-h1-to-title.lua -rw-r--r-- 600 bytes
c9a7db72Phil Hagelberg Remove broken contributors link until we can get it fixed. 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local title

-- Set title from level 1 headers, unless it has been set before.
function promote_header (header)
  if header.level >= 2 then
    return header
  end

  if not title then
    title = header.content
    return {}
  end

  local msg = '[WARNING] title already set; demoting header "%s"\n'
  io.stderr:write(msg:format(pandoc.utils.stringify(header)))
  header.level = header.level + 1
  return header
end

return {
  {Meta = function (meta) title = meta.title end}, -- init title
  {Header = promote_header},
  {Meta = function (meta) meta.title = title; return meta end}, -- set title
}